Skip to content

fix(python): don't credit a relative __import__ level as an external dependency - #829

Merged
rowkav09 merged 1 commit into
mainfrom
fix-dynamic-level
Oct 3, 2026
Merged

rowkav09 merged 1 commit into
mainfrom
fix-dynamic-level

Conversation

@rowkav09

@rowkav09 rowkav09 commented Oct 3, 2026

Copy link
Copy Markdown
Member

Fixes #828.

__import__("requests", level=1) and __import__("requests", globals(), locals(), [], 1) were recorded as usage of the external requests. 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).

…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.
@rowkav09
rowkav09 merged commit 1c5a5b3 into main Oct 3, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: __import__(name, level=1) is credited as an external dependency

1 participant