René's URL Explorer Experiment


Title: LOAD_ATTR specialization for ModuleType subclasses bypasses data descriptors on the subclass (3.14 regression) · Issue #156399 · python/cpython · GitHub

Open Graph Title: LOAD_ATTR specialization for ModuleType subclasses bypasses data descriptors on the subclass (3.14 regression) · Issue #156399 · python/cpython

X Title: LOAD_ATTR specialization for ModuleType subclasses bypasses data descriptors on the subclass (3.14 regression) · Issue #156399 · python/cpython

Description: Bug report Bug description: Since 3.14, attribute loads on an instance of a types.ModuleType subclass are specialized to LOAD_ATTR_MODULE, which reads the module dictionary directly. The specialization does not check whether the subclass...

Open Graph Description: Bug report Bug description: Since 3.14, attribute loads on an instance of a types.ModuleType subclass are specialized to LOAD_ATTR_MODULE, which reads the module dictionary directly. The specializa...

X Description: Bug report Bug description: Since 3.14, attribute loads on an instance of a types.ModuleType subclass are specialized to LOAD_ATTR_MODULE, which reads the module dictionary directly. The specializa...

Opengraph URL: https://github.com/python/cpython/issues/156399

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.112.3


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"LOAD_ATTR specialization for ModuleType subclasses bypasses data descriptors on the subclass (3.14 regression)","articleBody":"# Bug report\n\n### Bug description:\n\nSince 3.14, attribute loads on an instance of a `types.ModuleType`\nsubclass are specialized to `LOAD_ATTR_MODULE`, which reads the module\ndictionary directly. The specialization does not check whether the\nsubclass defines a data descriptor for the name, so after the first\naccess a data descriptor on the subclass is silently bypassed and the\ndictionary value is returned instead. Before 3.14 the guard was\n`PyModule_CheckExact`, so subclasses never took this path and the\ndescriptor was honoured on every access.\n\nThe following runs the reproducer on 3.13, 3.14, 3.14t, 3.15 and\n3.15t using [uv](https://docs.astral.sh/uv/):\n\n```sh\nfor v in 3.13 3.14 3.14t 3.15 3.15t; do uv run --no-project --python $v python - \u003c\u003c'EOF'\nimport sys\nimport sysconfig\nimport types\n\n\nclass Desc:\n    def __get__(self, instance, owner=None):\n        return \"from descriptor\"\n\n    def __set__(self, instance, value):\n        instance.__dict__[\"x\"] = value\n\n\nclass Module(types.ModuleType):\n    pass\n\n\nModule.x = Desc()\n\nm = Module(\"m\")\nm.__dict__[\"x\"] = \"from dict\"\n\nbuild = \"free-threaded\" if sysconfig.get_config_var(\"Py_GIL_DISABLED\") else \"default\"\nprint(sys.version.split()[0], build, [m.x for _ in range(4)])\nEOF\ndone\n```\n\nOutput:\n\n```\n3.13.15 default ['from descriptor', 'from descriptor', 'from descriptor', 'from descriptor']\n3.14.7 default ['from descriptor', 'from dict', 'from dict', 'from dict']\n3.14.7 free-threaded ['from descriptor', 'from dict', 'from dict', 'from dict']\n3.15.0rc1 default ['from descriptor', 'from dict', 'from dict', 'from dict']\n3.15.0rc1 free-threaded ['from descriptor', 'from dict', 'from dict', 'from dict']\n```\n\nExpected output is four \"from descriptor\" values on every version, as\non 3.13.\n\nThe first access runs through the general path and honours the\ndescriptor; the instruction is then specialized and subsequent\nexecutions read `m.__dict__[\"x\"]`. `getattr(m, \"x\")` returns\n\"from descriptor\" every time, since it does not go through the\nspecialized instruction, so the same expression gives different\nanswers depending on how it is spelled and how many times it has run.\n\nExpected: a data descriptor on the type takes precedence over the\ninstance dictionary for a module subclass exactly as it does for any\nother class, and as it did on 3.13 and earlier.\n\nObserved on 3.14.7 and 3.15.0rc1, both default and free-threaded\nbuilds; the same code is on `main`.\n\n## Cause\n\nIn `Python/specialize.c`, `_Py_Specialize_LoadAttr` selects the module\npath with\n\n```c\nelse if (Py_TYPE(owner)->tp_getattro == PyModule_Type.tp_getattro) {\n    fail = specialize_module_load_attr(owner, instr, name);\n}\n```\n\nwhich any `ModuleType` subclass that does not override\n`__getattribute__` or `__getattr__` satisfies.\n`specialize_module_load_attr_lock_held` then only inspects the module\ndictionary (unicode keys, no `__getattr__` entry, the name present,\na keys version); it never looks the name up on the type. The guard of\nthe emitted `LOAD_ATTR_MODULE` is likewise only the dict keys version,\nso a descriptor added to the type later is not noticed either.\n\nThis came in with gh-103951 (\"Fast attribute access for module\nsubclasses\", PR #126264, merged 2024-11-15), which relaxed the guard\nfrom `PyModule_CheckExact` for speed. The discussion there was about\nkeeping the guard cheap: `PyModule_Check` was rejected because it\nwalks the MRO, and the `tp_getattro` comparison was chosen as a single\npointer compare that admits only types with module attribute\nsemantics. The stated motivation was the \"Customizing module attribute\naccess\" pattern from the data model docs, that is, assigning a\n`ModuleType` subclass to a module's `__class__`. Neither the issue\ncomments nor the PR body, review threads or comments mention\ndescriptors, `property`, or type version tags, so this looks like an\nunintended consequence rather than a decision. A search of the\ntracker (LOAD_ATTR_MODULE, module subclass descriptor, ModuleType\nsubclass property, and similar) found no prior report.\n\n## Impact\n\nAny library that assigns a `ModuleType` subclass to a module's\n`__class__` in order to intercept attribute access with descriptors\n(the documented route for module-level properties and lazy\nattributes, per the \"Customizing module attribute access\" section of\nthe data model docs) sees the interception disappear after the first\naccess on 3.14+. The workaround is to define a `__getattribute__` on\nthe subclass that delegates to the base, which gives the type its own\n`tp_getattro` and so avoids the specialization, at the cost of a\nPython-level call on every attribute access to that module.\n\nEncountered in wrapture (https://github.com/GrahamDumpleton/wrapture),\nwhich uses exactly this technique to intercept module attribute access;\nrepro above is reduced from that.\n\n## AI Disclaimer\n\nThis was a real problem I encountered, but have had AI generate the report for me so more clearly explained. The AI did generate a suggested fix as well, but I am not in a position to evaluate whether it is correct so have not included it. If want AI generated suggested fix then let me know.\n\n### CPython versions tested on:\n\n3.14\n\n### Operating systems tested on:\n\nmacOS\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-156474\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/GrahamDumpleton","@type":"Person","name":"GrahamDumpleton"},"datePublished":"2026-08-26T04:02:30Z","url":"https://github.com/python/cpython/issues/156399"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:6d5e0851-f884-5979-088d-dae1af55edfc
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9012:39588:E5CE8F:13388C5:6B064BBA
html-safe-noncecd8069309dad10dc8c5ed269fe4971691ab1271181d9068f66a4d50ff555eefe
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MDEyOjM5NTg4OkU1Q0U4RjoxMzM4OEM1OjZCMDY0QkJBIiwidmlzaXRvcl9pZCI6IjQ3NDMzMzQwMTc3NTAxNTgyNjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac815e65c2b56da85883195270e0f7c0e5d6038f5c4aa56db3a783bd8574289645
hovercard-subject-tagissue:5253192809
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/156399/issue_layout
twitter:imagehttps://opengraph.githubassets.com/6caccef90bbba706180844d9084a44c47476a2f04a30779055353eda0003f580/python/cpython/issues/156399
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/6caccef90bbba706180844d9084a44c47476a2f04a30779055353eda0003f580/python/cpython/issues/156399
og:image:altBug report Bug description: Since 3.14, attribute loads on an instance of a types.ModuleType subclass are specialized to LOAD_ATTR_MODULE, which reads the module dictionary directly. The specializa...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameGrahamDumpleton
hostnamegithub.com
expected-hostnamegithub.com
None772b6997ca4daa0428dd49a25d76052e765555ae560fe9c88517eb828bbd861e
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasef1f9a08f7c769a37f1dfc18ad43d463c222a7eea
ui-targetcanary-1
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/156399#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F156399
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F156399
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/156399
Reloadhttps://github.com/python/cpython/issues/156399
Reloadhttps://github.com/python/cpython/issues/156399
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/156399
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/156399
#156474https://github.com/python/cpython/pull/156474
LOAD_ATTR specialization for ModuleType subclasses bypasses data descriptors on the subclass (3.14 regression)https://github.com/python/cpython/issues/156399#top
#156474https://github.com/python/cpython/pull/156474
3.14https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
3.15https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
3.16https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.16%22
interpreter-corehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
type-bughttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/GrahamDumpleton
GrahamDumpletonhttps://github.com/GrahamDumpleton
on Aug 26, 2026https://github.com/python/cpython/issues/156399#issue-5253192809
uvhttps://docs.astral.sh/uv/
gh-103951https://github.com/python/cpython/issues/103951
#126264https://github.com/python/cpython/pull/126264
https://github.com/GrahamDumpleton/wrapturehttps://github.com/GrahamDumpleton/wrapture
gh-156399: Don't specialize LOAD_ATTR_MODULE for module subclasses #156474https://github.com/python/cpython/pull/156474
GrahamDumpletonhttps://github.com/GrahamDumpleton
type-bughttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
on Aug 26, 2026https://github.com/python/cpython/issues/156399#event-30020330514
aiskhttps://github.com/aisk
interpreter-corehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
3.14https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
3.15https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
3.16https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.16%22
on Aug 26, 2026https://github.com/python/cpython/issues/156399#event-30020677056
markshannonhttps://github.com/markshannon
on Oct 22, 2026https://github.com/python/cpython/issues/156399#event-34004473456
gh-156399: Don't specialize LOAD_ATTR_MODULE for module subclasses (G…https://github.com/python/cpython/commit/85599d33d734c9e586f0dd9b7fc87ec0b9f2a6b5
gh-156399https://github.com/python/cpython/issues/156399
G…https://github.com/python/cpython/pull/156474
85599d3https://github.com/python/cpython/commit/85599d33d734c9e586f0dd9b7fc87ec0b9f2a6b5
markshannonhttps://github.com/markshannon
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#156474https://github.com/python/cpython/pull/156474
on Oct 22, 2026https://github.com/python/cpython/issues/156399#event-34004473822
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/156399
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/156399
3.14https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
3.15https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
3.16https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.16%22
interpreter-corehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
type-bughttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlmax-age=0, private, must-revalidate

Viewport: width=device-width


URLs of crawlers that visited me.