Skip to content

lazy imports filter sees the same thing for from x import y and from .x import y #148110

Closed

Description

@pablogsal

The lazy imports filter gets the unresolved module name for relative imports, so lazy from target import VALUE and lazy from .target import VALUE look identical to the callback even though they resolve to different modules. In this repro both filter calls print ('pkg.runner', 'target', ('VALUE',)), so the filter cannot tell the absolute and relative cases apart.

$ tmpdir=$(mktemp -d)
$ mkdir -p "$tmpdir/pkg"
$ cat > "$tmpdir/target.py" <<'PY'
VALUE = 'absolute'
PY
$ cat > "$tmpdir/pkg/__init__.py" <<'PY'
PY
$ cat > "$tmpdir/pkg/target.py" <<'PY'
VALUE = 'relative'
PY
$ cat > "$tmpdir/pkg/runner.py" <<'PY'
import sys

def my_filter(importer, name, fromlist):
    print((importer, name, fromlist))
    return True

sys.set_lazy_imports_filter(my_filter)
lazy from target import VALUE as absolute_value
lazy from .target import VALUE as relative_value
PY
$ PYTHONPATH="$tmpdir" ./python -c 'import pkg.runner'
('pkg.runner', 'target', ('VALUE',))
('pkg.runner', 'target', ('VALUE',))

Linked PRs

Activity

  1. changed the title [-]sys.set_lazy_imports_filter cannot distinguish \ from \[/-] [+]lazy imports filter sees the same thing for `from x import y` and `from .x import y`[/+] on Apr 4, 2026
  2. added a commit that references this issue on Apr 4, 2026
  3. pablogsal commented on Apr 4, 2026

    @pablogsal
    MemberAuthor
  4. picnixz commented on Apr 4, 2026

    @picnixz
  5. added a commit that references this issue on Apr 6, 2026
  6. added a commit that references this issue on Apr 25, 2026
  7. added a commit that references this issue on Sep 23, 2026
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

    3.15bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)topic-lazy-importstype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions