-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
Closed
Labels
3.15new features, bugs and security fixesnew features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
At runtime, types.LazyImportType is an uninitialized static type (unless you e.g. access types.LazyImportType.resolve first).
This can lead to funky behaviors:
lazy import wave, traceback
try:
help(globals()['wave'].resolve) # However, a call ".resolve()" would work
except AttributeError as e:
print(e) # 'lazy_import' object has no attribute 'resolve'
try:
help(globals()['wave'].resolve)
except AttributeError:
# traceback.format_exc() initializes types.LazyImportType as a side effect.
# This prints "AttributeError: 'lazy_import' object has no attribute 'resolve'".
print(traceback.format_exc().splitlines()[-1])
print(globals()['wave'].resolve) # Succeeds.The solution I found is to add &PyLazyImport_Type to static_types[], the array of types initialized in _PyTypes_InitTypes during interpreter startup.
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
3.15new features, bugs and security fixesnew features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error