Title: PEP 810 lazy from imports ignore module `__getattr__` when reifying · Issue #144957 · python/cpython · GitHub
Open Graph Title: PEP 810 lazy from imports ignore module `__getattr__` when reifying · Issue #144957 · python/cpython
X Title: PEP 810 lazy from imports ignore module `__getattr__` when reifying · Issue #144957 · python/cpython
Description: Bug report Bug description: Without lazy imports: python -c "from typing import Match; print(Match)" typing.Match With lazy imports: python -c "lazy from typing import Match; print(Match)" Traceback (most recent call last): File " Open Graph Description: Bug report Bug description: Without lazy imports: python -c "from typing import Match; print(Match)" typing.Match With lazy imports: python -c "lazy from typing import Match; print(Match)" Tracebac...
X Description: Bug report Bug description: Without lazy imports: python -c "from typing import Match; print(Match)" typing.Match With lazy imports: python -c "lazy from typing import Match; print(M...
Opengraph URL: https://github.com/python/cpython/issues/144957
X: @github
Domain: github.com
Links:
Viewport: width=device-width
Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"PEP 810 lazy from imports ignore module `__getattr__` when reifying","articleBody":"# Bug report\n\n### Bug description:\n\nWithout lazy imports:\n`python -c \"from typing import Match; print(Match)\"`\n\n```\ntyping.Match\n```\n\nWith lazy imports:\n`python -c \"lazy from typing import Match; print(Match)\"`\n\n```\nTraceback (most recent call last):\n File \"\u003cstring\u003e\", line 1, in \u003cmodule\u003e\n lazy from typing import Match; print(Match)\nImportError: deferred import of 'typing.Match' raised an exception during resolution\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"\u003cstring\u003e\", line 1, in \u003cmodule\u003e\n lazy from typing import Match; print(Match)\n ^^^^^\nImportError: cannot import name 'Match' from 'typing' (.../src/cpython/Lib/typing.py)\n```\n\n---\n\nI believe the underlying issue is that the lazy import statement creates a `lazy_import` object in the module `__dict__` which then prevents the module `__getattr__` from being called. This occurs even if the module has already been imported.\n\n`demo_module.py`\n\n```python\ndef __getattr__(name):\n return name\n```\n\n`demo_script.py`\n```python\nimport demo_module\nlazy from demo_module import ohno\n\ntry:\n print(ohno)\nexcept ImportError:\n print(\"Import failed\")\n\n# The lazy from import has placed the ohno object in demo_module's globals\ntry:\n print(demo_module.ohno)\nexcept ImportError:\n print(\"Failed again\")\n\nprint({k: v for k, v in demo_module.__dict__.items() if not k.startswith(\"_\")})\n\ndemo_module.__dict__.pop(\"ohno\", None)\nprint(demo_module.ohno)\n```\n\n`python demo_script.py`\n```\nImport failed\nFailed again\n{'ohno': \u003clazy_import 'demo_module.ohno'\u003e}\nohno\n```\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\n_No response_\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-145330\n* gh-149624\n* gh-149678\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/DavidCEllis","@type":"Person","name":"DavidCEllis"},"datePublished":"2026-02-18T13:48:08.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/144957/cpython/issues/144957"}
route-pattern /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) route-controller voltron_issues_fragments route-action issue_layout fetch-nonce v2:f9caceff-b065-8d6e-0b72-6efb137e8a54 current-catalog-service-hash 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 request-id B702:9BDE:4E1C9A3:6CD4575:6A50F1ED html-safe-nonce 20a15a17a2ac738e252c3f78c8014549283eb7db2f1c53552abccdd1eccc1560 visitor-payload eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNzAyOjlCREU6NEUxQzlBMzo2Q0Q0NTc1OjZBNTBGMUVEIiwidmlzaXRvcl9pZCI6IjYzOTY5MjgzMjk3MTUzNDc5NDkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== visitor-hmac 455a12c798555fa36cf5aa939558b100d1a7555bb56e886c21df978125da941f hovercard-subject-tag issue:3957958634 github-keyboard-shortcuts repository,issues,copilot google-site-verification Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I octolytics-url https://collector.github.com/github/collect analytics-location / fb:app_id 1401488693436528 apple-itunes-app app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/144957/issue_layout twitter:image https://opengraph.githubassets.com/da866068291d7b91859ced8920afb73956589c173ac13900538cc96fa2bde075/python/cpython/issues/144957 twitter:card summary_large_image og:image https://opengraph.githubassets.com/da866068291d7b91859ced8920afb73956589c173ac13900538cc96fa2bde075/python/cpython/issues/144957 og:image:alt Bug report Bug description: Without lazy imports: python -c "from typing import Match; print(Match)" typing.Match With lazy imports: python -c "lazy from typing import Match; print(Match)" Tracebac... og:image:width 1200 og:image:height 600 og:site_name GitHub og:type object og:author:username DavidCEllis hostname github.com expected-hostname github.com None 5266e58c17a510c403505cc811606465e90a881d2007ee7df1c4800d5c659838 turbo-cache-control no-preview go-import github.com/python/cpython git https://github.com/python/cpython.git octolytics-dimension-user_id 1525981 octolytics-dimension-user_login python octolytics-dimension-repository_id 81598961 octolytics-dimension-repository_nwo python/cpython octolytics-dimension-repository_public true octolytics-dimension-repository_is_fork false octolytics-dimension-repository_network_root_id 81598961 octolytics-dimension-repository_network_root_nwo python/cpython turbo-body-classes logged-out env-production page-responsive disable-turbo false browser-stats-url https://api.github.com/_private/browser/stats browser-errors-url https://api.github.com/_private/browser/errors release 5ec60191a48933536a90c8a19f47142fcd0d4739 ui-target canary-2 theme-color #1e2327 color-scheme light dark
URLs of crawlers that visited me.