Skip to content

Non-module namespaces don't watch for lazy imports #151619

@brandtbucher

Description

@brandtbucher

Bug report

Example:

>>> c = """ 
... X = None
... 
... def f():
...     return X
... 
... # Specialize the global load X:
... f()
... f()
... 
... # Replace it with a lazy placeholder:
... lazy import X
... 
... # Lazy import not resolved, cached lookup used instead:
... print(f())
... """
>>> exec(c, {})
<lazy_import 'X'>

We need to ensure that a watcher is installed on the global (and probably builtin?) namespaces when specializing global loads, just in case they aren't actual module __dicts__. I'll open a PR soon.

Metadata

Metadata

Assignees

Labels

3.15pre-release feature fixes, bugs and security fixes3.16new features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)topic-lazy-importstype-bugAn unexpected behavior, bug, or error
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions