Skip to content

types.LazyImportType is not initialized #145452

Closed

Description

@johnslavik

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

Activity

  1. self-assigned this
    on Mar 3, 2026
  2. added
    type-bugAn unexpected behavior, bug, or error
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    3.15bugs and security fixes
    on Mar 3, 2026
  3. johnslavik commented on Mar 3, 2026

    @johnslavik
    MemberAuthor
  4. added a commit that references this issue on Mar 3, 2026
  5. added a commit that references this issue on Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

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

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions