Skip to content

Module __getattr__ doesn't work with lazy import #149623

@JelleZijlstra

Description

@JelleZijlstra

Bug report

Bug description:

typing.ForwardRef is defined through a module __getattr__. This breaks with lazy imports:

$ ./python.exe -c 'lazy from typing import ForwardRef; print(ForwardRef)'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
    lazy from typing import ForwardRef; print(ForwardRef)
ImportError: deferred import of 'typing.ForwardRef' raised an exception during resolution

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

Traceback (most recent call last):
  File "<string>", line 1, in <module>
    lazy from typing import ForwardRef; print(ForwardRef)
                                              ^^^^^^^^^^
ImportError: cannot import name 'ForwardRef' from 'typing' (/Users/jelle/py/cpython/Lib/typing.py)

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions