Skip to content

Python: importlib alias rebind index skips wildcard imports #853

Description

@rowkav09

Priority: P3. Regression in the alias indexing added for #847/#848, reproduced on bab7689.

import importlib as il
from other import *
il.import_module("requests")

The extractor credits requests as a dynamic import. A wildcard import can overwrite il, so the existing conservative rebind rule should drop that alias. The same happens to aliases of import_module and import.

rebinds() already treats from other import * as a possible rebinding of every name. The new identifier index only selects statements mentioning the alias, so the wildcard statement never reaches that check.

Fix: include wildcard-import statements in each alias's candidate statements, retaining the existing scope checks and identifier index for other statements. This restores the pre-indexing behavior. It is intentionally conservative: a wildcard import that does not actually export the alias still loses dynamic-import credit, as before.

A fail-first extractor test covers module/function/import aliases and unchanged no-wildcard controls. It fails on current main and passes with the proposed patch. No real Python application or end-to-end unused-dependency deletion was tested.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions