René's URL Explorer Experiment


Title: Incorrect value for `Py_TPFLAGS_MANAGED_DICT` in `Lib/test/test_class.py` · Issue #136535 · python/cpython · GitHub

Open Graph Title: Incorrect value for `Py_TPFLAGS_MANAGED_DICT` in `Lib/test/test_class.py` · Issue #136535 · python/cpython

X Title: Incorrect value for `Py_TPFLAGS_MANAGED_DICT` in `Lib/test/test_class.py` · Issue #136535 · python/cpython

Description: I've noticed a discrepancy in the value of the Py_TPFLAGS_MANAGED_DICT flag constant used in Lib/test/test_class.py. Summary The test file Lib/test/test_class.py defines a local constant Py_TPFLAGS_MANAGED_DICT = (1 << 2). However, the c...

Open Graph Description: I've noticed a discrepancy in the value of the Py_TPFLAGS_MANAGED_DICT flag constant used in Lib/test/test_class.py. Summary The test file Lib/test/test_class.py defines a local constant Py_TPFLAGS...

X Description: I've noticed a discrepancy in the value of the Py_TPFLAGS_MANAGED_DICT flag constant used in Lib/test/test_class.py. Summary The test file Lib/test/test_class.py defines a local constant Py_TPF...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Incorrect value for `Py_TPFLAGS_MANAGED_DICT` in `Lib/test/test_class.py`","articleBody":"I've noticed a discrepancy in the value of the `Py_TPFLAGS_MANAGED_DICT` flag constant used in `Lib/test/test_class.py`.\n\n### Summary\n\nThe test file `Lib/test/test_class.py` defines a local constant `Py_TPFLAGS_MANAGED_DICT = (1 \u003c\u003c 2)`. However, the canonical definition in the C header `Include/object.h` is `Py_TPFLAGS_MANAGED_DICT = (1 \u003c\u003c 4)`.\n\nThe existing tests that use this constant pass only coincidentally. They test plain classes which happen to have a flag set at the `(1 \u003c\u003c 2)` position, but this is not the actual managed dictionary flag.\n\nThis can be proven by a test case that uses a `__slots__` class. Such a class should not have a managed dictionary, and therefore, a test checking for the `MANAGED_DICT` flag should result in `0`. However, the test written to check for the incorrect `(1 \u003c\u003c 2)` flag also results in `0`, which causes an assertion to fail, proving the constant is wrong.\n\n### Proof of Incorrect Constant\n\nThe following test case demonstrates that the `(1 \u003c\u003c 2)` constant is incorrect. It uses a `__slots__` class, which is known not to have a managed dictionary.\n\nThe test attempts to assert that this class *has* the flag specified by the incorrect `(1 \u003c\u003c 2)` constant. This assertion fails, providing evidence that the constant is wrong.\n\n```python\n# In Lib/test/test_class.py\nimport unittest\n\nclass TestMisleadingConstant(unittest.TestCase):\n    def test_slots_class_reveals_flaw_in_constant(self):\n        # The incorrect constant as defined in test_class.py\n        Py_TPFLAGS_MANAGED_DICT_WRONG = (1 \u003c\u003c 2)\n        # The correct constant from object.h\n        Py_TPFLAGS_MANAGED_DICT_CORRECT = (1 \u003c\u003c 4)\n\n        class NoManagedDict:\n            __slots__ = ('a',)\n\n        # First, confirm that a __slots__ class correctly does NOT have\n        # the true managed dict flag. This assertion passes.\n        self.assertEqual(\n            NoManagedDict.__flags__ \u0026 Py_TPFLAGS_MANAGED_DICT_CORRECT,\n            0,\n            \"A __slots__ class should not have the correct MANAGED_DICT flag (1\u003c\u003c4)\"\n        )\n\n        # Next, try to assert that this class HAS the flag at the (1\u003c\u003c2) position.\n        # This assertion FAILS with \"AssertionError: 0 != 4\", because a __slots__ class\n        # does not have this flag either.\n        # This failure is the proof that the (1\u003c\u003c2) constant is wrong for this purpose.\n        self.assertEqual(\n            NoManagedDict.__flags__ \u0026 Py_TPFLAGS_MANAGED_DICT_WRONG,\n            Py_TPFLAGS_MANAGED_DICT_WRONG,\n            \"This fails, proving the constant is wrong.\"\n        )\n```\n\n### Reference Links\n\n1.  **Incorrect constant in `test_class.py`**:\n    *   https://github.com/python/cpython/blob/49365bd110a254a6a304d2f880482bfeb2e4490d/Lib/test/test_class.py#L862\n\n2.  **Correct constant definition in `object.h`**:\n    *   https://github.com/python/cpython/blob/49365bd110a254a6a304d2f880482bfeb2e4490d/Include/object.h#L532-L535\n\n### Proposed Fix\n\nThe constant `Py_TPFLAGS_MANAGED_DICT` in `Lib/test/test_class.py` should be updated to `(1 \u003c\u003c 4)` to match the C header definition.\nAdditionally, we could add a test case for a class that does not have `Py_TPFLAGS_INLINE_VALUES`.\n\nIf this analysis seems correct, I would be happy to open a Pull Request to update the constant and add a corresponding test case. \n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-136538\n* gh-140532\n* gh-140533\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/ever0de","@type":"Person","name":"ever0de"},"datePublished":"2025-07-11T10:10:55.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/136535/cpython/issues/136535"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:ff0789f2-7cfd-35cd-57a9-45ac1a0acf3c
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idD196:2C09F1:717436:911E31:696B1536
html-safe-nonceaaafb21addefc4e23d754cf57bfffe20a9795c36b0a1a263921b7d7618c7b09b
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMTk2OjJDMDlGMTo3MTc0MzY6OTExRTMxOjY5NkIxNTM2IiwidmlzaXRvcl9pZCI6IjgwMTg0NjExMDU5NDk3MDk2MjIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacbdbf89badf476c8fc5ac70b44aa9c2edb2b65f02c5621cffa935aa583315f6dc
hovercard-subject-tagissue:3222352400
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/136535/issue_layout
twitter:imagehttps://opengraph.githubassets.com/7b3aecb67e2e81d29c18bdc3f985fba8c95cdc63d075fe7a951247050ac76aa2/python/cpython/issues/136535
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/7b3aecb67e2e81d29c18bdc3f985fba8c95cdc63d075fe7a951247050ac76aa2/python/cpython/issues/136535
og:image:altI've noticed a discrepancy in the value of the Py_TPFLAGS_MANAGED_DICT flag constant used in Lib/test/test_class.py. Summary The test file Lib/test/test_class.py defines a local constant Py_TPFLAGS...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameever0de
hostnamegithub.com
expected-hostnamegithub.com
None5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d
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
release82560a55c6b2054555076f46e683151ee28a19bc
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/issues/136535#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F136535
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
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
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://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/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F136535
Sign up https://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/136535
Reloadhttps://github.com/python/cpython/issues/136535
Reloadhttps://github.com/python/cpython/issues/136535
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/136535
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 33.9k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 71.1k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.1k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects 31 https://github.com/python/cpython/projects
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/python/cpython/security
Please reload this pagehttps://github.com/python/cpython/issues/136535
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/136535
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/136535
Incorrect value for Py_TPFLAGS_MANAGED_DICT in Lib/test/test_class.pyhttps://github.com/python/cpython/issues/136535#top
testsTests in the Lib/test dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22tests%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/ever0de
https://github.com/ever0de
ever0dehttps://github.com/ever0de
on Jul 11, 2025https://github.com/python/cpython/issues/136535#issue-3222352400
cpython/Lib/test/test_class.pyhttps://github.com/python/cpython/blob/49365bd110a254a6a304d2f880482bfeb2e4490d/Lib/test/test_class.py#L862
49365bdhttps://github.com/python/cpython/commit/49365bd110a254a6a304d2f880482bfeb2e4490d
cpython/Include/object.hhttps://github.com/python/cpython/blob/49365bd110a254a6a304d2f880482bfeb2e4490d/Include/object.h#L532-L535
49365bdhttps://github.com/python/cpython/commit/49365bd110a254a6a304d2f880482bfeb2e4490d
gh-136535: Tests: Correct Py_TPFLAGS_MANAGED_DICT in test_class.py #136538https://github.com/python/cpython/pull/136538
[3.14] gh-136535: Tests: Correct Py_TPFLAGS_MANAGED_DICT in test_class.py (gh-136538) #140532https://github.com/python/cpython/pull/140532
[3.13] gh-136535: Tests: Correct Py_TPFLAGS_MANAGED_DICT in test_class.py (gh-136538) #140533https://github.com/python/cpython/pull/140533
testsTests in the Lib/test dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22tests%22
type-bugAn unexpected behavior, bug, or errorhttps://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

Viewport: width=device-width


URLs of crawlers that visited me.