Repository navigation
fix(python): don't credit a relative __import__ level as an external dependency - #829
Merged
Merged
Conversation
…dependency Read the call arguments and skip __import__ calls with a positive integer level (keyword or fifth positional). Level 0 and a level that is not a plain integer literal keep the existing credit. Fixes #828.
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.
Fixes #828.
__import__("requests", level=1)and__import__("requests", globals(), locals(), [], 1)were recorded as usage of the externalrequests. A positive level is package-relative, so those calls are now skipped. The call arguments are read with a depth-aware split, not a regex over the whole call:level=as a keyword or the fifth positional argument, as an integer literal (decimal, hex, octal, binary, underscores, parenthesised).Kept as before: level 0, no level, and a level that is not a plain integer literal (
level=lvl,n + 1,*args). Those are not provably relative, so they keep the credit rather than risk a used dependency being flagged as unused.level=inside a nested call is ignored.importlib.import_module(".x", package="app")was already skipped by its leading dot; tests added.Tests: 20 call shapes, fail on main, adapter suite passes (259).