fix: make extra_name of try_import optional and the install hint reusable - #2247
Merged
Merged
Conversation
…reusable `extra_name` was introduced in #2208 as a required keyword-only argument. All call sites inside this package were updated in the same PR, so requiring it gained nothing internally, but it silently broke every external caller of the helper in what shipped as a patch release (1.10.1). The Apify SDK guards its Scrapy integration with this helper, so `import apify.scrapy` now fails on any fresh install: TypeError: try_import() missing 1 required keyword-only argument: 'extra_name' Giving `extra_name` a default restores that compatibility; every call site in this package passes it explicitly, so the messages users see are unchanged. While here: - Add a `package_name` argument, defaulting to this package. The install hint had the distribution name hardcoded, so a downstream package reusing the helper would point its users at `crawlee[<extra>]` for an extra that only exists in their own distribution. - Read the original message with `str(e)` instead of `e.args[0]`, which raised `IndexError` on an `ImportError` carrying no arguments — a case the docstring explicitly anticipates for nested guards. - Normalize `extra_name` to a list in `_get_install_hint` so an empty collection cannot raise `IndexError` either. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014KjVQGrzsBfgKerTpaVf3o
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2247 +/- ##
==========================================
- Coverage 93.73% 93.72% -0.01%
==========================================
Files 181 181
Lines 12877 12878 +1
==========================================
Hits 12070 12070
- Misses 807 808 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Pijukatel
added a commit
to apify/apify-sdk-python
that referenced
this pull request
Sep 22, 2026
It made backwards-incompatible changes to `crawlee._utils.try_import` Unreleased version of Crawlee 1.10.2 should include backwards compatible fix apify/crawlee-python#2247
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
extra_namelanded in #2208 as a required keyword-only argument in a patch release, breaking every external caller:import apify.scrapyfails withThis gives it a default — every call site here passes it explicitly, so user-facing messages are unchanged — and adds
package_name, since the hint hardcodedcrawlee[<extra>]and pointed SDK users at an extra that does not exist here.Also fixes two
IndexErroralready in the helper:e.args[0]on an arglessImportError(the nested-guard case the docstring anticipates), andextra_name[0]on an empty list.