-
- Notifications
You must be signed in to change notification settings - Fork 33k
Open
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
Create two files as follows:
main.py
:
import importlib.util import inspect import sys # https://docs.python.org/3/library/importlib.html#implementing-lazy-imports def lazy_import(name): spec = importlib.util.find_spec(name) loader = importlib.util.LazyLoader(spec.loader) spec.loader = loader module = importlib.util.module_from_spec(spec) sys.modules[name] = module loader.exec_module(module) return module lazy_import('m') f = inspect.currentframe() inspect.getframeinfo(f)
m.py
:
print("I'm loaded!")
Now run:
$ python main.py I'm loaded!
This behavior doesn't make much sense, since f
isn't even inside m
.
CPython versions tested on:
3.13
Operating systems tested on:
Linux
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error