GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Lazy imports may leave phantom unresolvable attributes in module · Issue #150052 · python/cpython

Lazy imports may leave phantom unresolvable attributes in module #150052

New issue
Copy link
New issue
Copy link
Closed
Closed
Lazy imports may leave phantom unresolvable attributes in module#150052
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-lazy-importstype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@DinoV
DinoV
opened on May 19, 2026
Issue body actions

Bug description:

@pablogsal brought this up at the sprints today. When doing "from .. import .." we track the "from" values to publish when on the module when it finally gets imported. We have no way to distinguish whether the values actually exist, if they're values within the package we're importing from, or if they're subpackages. When the module is imported we publish these values as LazyImportObjects on the module. Because we don't know if they exist or if they're subpackages they all get published as long as they don't already exist in the module potentially leaving some cruft around.

Initially this feels like it's "by design". But there's a few alternatives we should consider:

  1. Remove the LazyImportObject from the module if the value is attempted to be resolved but doesn't exist
  2. Switch to instead of publishing the value update _Py_module_getattro_impl to return these values. This is maybe more in the spirit of the changes we've made to push things into the module object in general. We'd publish nothing into the module but it would magically become available if we resolve it and then presumably we'd publish it into the module.
>>> lazy from json import noway
>>> import json
>>> dir(json)
['JSONDecodeError', 'JSONDecoder', 'JSONEncoder', '__all__', '__author__', '__builtins__', '__doc__', '__file__', '__getattr__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '_default_decoder', '_default_encoder', 'codecs', 'decoder', 'detect_encoding', 'dump', 'dumps', 'encoder', 'load', 'loads', 'noway', 'scanner']
>>> json.noway
Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 1319, in _find_and_load_unlocked
ImportError: deferred import of 'json.noway' raised an exception during resolution

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<python-input-3>", line 1, in <module>
    json.noway
ImportError: cannot import name 'noway' from 'json' (/home/dinoviehland/cpython_upstream/Lib/json/__init__.py)
>>> dir(json)
['JSONDecodeError', 'JSONDecoder', 'JSONEncoder', '__all__', '__author__', '__builtins__', '__doc__', '__file__', '__getattr__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '_default_decoder', '_default_encoder', 'codecs', 'decoder', 'detect_encoding', 'dump', 'dumps', 'encoder', 'load', 'loads', 'noway', 'scanner']
>>>

CPython versions tested on:

3.15

Operating systems tested on:

Linux

Linked PRs

  • [3.15] gh-150052: Modules resolve pending lazy attributes #150054
  • [3.15] gh-150052: Resolve un-loaded lazily loaded submodules via module.__getattr__ instead of publishing lazy values #150055
  • gh-150052: Resolve un-loaded lazily loaded submodules via module.__getattr__ instead of publishing lazy values (#150055) #150744
Reacted by Xuwz
Reacted by Petr Viktorin

Activity

  1. DinoV
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    topic-lazy-imports
    on May 19, 2026
  2. StanFromIreland
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on May 19, 2026
  3. pablogsal
    added a commit that references this issue on May 19, 2026

    [3.15] gh-150052: Resolve un-loaded lazily loaded submodules via modu…

    6847f4b
  4. pablogsal
    added a commit that references this issue on Jun 2, 2026

    gh-150052: Resolve un-loaded lazily loaded submodules via `module.__g…

    5a2d273
  5. pablogsal
    closed this as completedon Jun 2, 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

    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-lazy-importstype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.