Title: Conformance suite: Questionable tests in dataclasses_descriptors.py · Issue #2259 · python/typing · GitHub
Open Graph Title: Conformance suite: Questionable tests in dataclasses_descriptors.py · Issue #2259 · python/typing
X Title: Conformance suite: Questionable tests in dataclasses_descriptors.py · Issue #2259 · python/typing
Description: The dataclasses_descriptors.py test case has a comment "This portion of the dataclass spec is under-specified in the documentation, but its behavior can be determined from the runtime implementation." However, some of the behaviors in te...
Open Graph Description: The dataclasses_descriptors.py test case has a comment "This portion of the dataclass spec is under-specified in the documentation, but its behavior can be determined from the runtime implementatio...
X Description: The dataclasses_descriptors.py test case has a comment "This portion of the dataclass spec is under-specified in the documentation, but its behavior can be determined from the runtime implemen...
Opengraph URL: https://github.com/python/typing/issues/2259
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Conformance suite: Questionable tests in dataclasses_descriptors.py","articleBody":"The [dataclasses_descriptors.py](https://github.com/python/typing/blob/main/conformance/tests/dataclasses_descriptors.py) test case has a comment \"This portion of the dataclass spec is under-specified in the documentation, but its behavior can be determined from the runtime implementation.\"\nHowever, some of the behaviors in tests don't align with the runtime behavior.\n\nThe first part, which is using a data descriptor `Desc1` and a dataclass `DC1`, is fine.\n\nThen we get this, where `Desc2` is a non-data descriptor (only implementing `__get__`):\n\n```python\n@dataclass\nclass DC2:\n x: Desc2[int]\n y: Desc2[str]\n z: Desc2[str] = Desc2()\n\n\nassert_type(DC2.x, list[int])\nassert_type(DC2.y, list[str])\nassert_type(DC2.z, list[str])\n```\n\nHowever, `DC2.x` and `DC2.y` are AttributeErrors at runtime, because there is no `Desc2` object in the runtime class dictionary. I don't know if we should require type checkers to produce an error but certainly we should allow it.\n\nThen we construct a `DC2` object:\n\n```python\n\ndc2 = DC2(Desc2(), Desc2(), Desc2())\nassert_type(dc2.x, int)\nassert_type(dc2.y, str)\nassert_type(dc2.z, str)\n```\n\nBut at runtime, `dc2`'s three attributes are all just those `Desc2` objects, not ints or strs, because those objects are stored as instance attributes, so the descriptor protocol never runs on them.\n\nThe more complicated case is the `z` attribute, which has a `Desc2` object stored in the class. Dataclasses would conventionally treat this as the default, but it gets the default by conventional access in the class body, which calls the descriptor's `__get__` with obj=None. So the runtime default for this field is actually the value you'd get for accessing `DC2.z`, which is `list[str]`.\n\nLooking at actual type checker behavior, I think pyrefly gets all this pretty much right (which means it fails the test). Mypy and pyright pass the test, but their behavior is wrong.\n\nSince (as the test acknowledges) the behavior is not fully specified, perhaps it is best to delete this test from the conformance suite for now, until we come up with a full specification for the behavior of descriptors in dataclasses.","author":{"url":"https://github.com/JelleZijlstra","@type":"Person","name":"JelleZijlstra"},"datePublished":"2026-04-14T02:36:35Z","url":"https://github.com/python/typing/issues/2259"}
| react-profiling | 0 |
| react-import-map | react,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-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7e599b22-4eff-b331-8281-92f6923ac716 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C526:3F7946:674B73:8B6F22:6AFF8C81 |
| html-safe-nonce | 658d821129b746ddae0be9129b5b5999135a7e1a1e75094ffaaea6be5967651b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNTI2OjNGNzk0Njo2NzRCNzM6OEI2RjIyOjZBRkY4QzgxIiwidmlzaXRvcl9pZCI6IjY5MTcyODU3NDk2MDM2NjcwNzMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 79bc2312ad5d43c8e119cd9e0d73ab6d00098179a08e988d93d27c6c76828a36 |
| hovercard-subject-tag | issue:4259122341 |
| 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/typing/2259/issue_layout |
| twitter:image | https://opengraph.githubassets.com/64941c0973497f31e43bb2612f91c8b2be03e614c9f2cef6419b2b79df25c148/python/typing/issues/2259 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/64941c0973497f31e43bb2612f91c8b2be03e614c9f2cef6419b2b79df25c148/python/typing/issues/2259 |
| og:image:alt | The dataclasses_descriptors.py test case has a comment "This portion of the dataclass spec is under-specified in the documentation, but its behavior can be determined from the runtime implementatio... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JelleZijlstra |
| hostname | github.com |
| expected-hostname | github.com |
| None | 587ad99a3e443b2e1cb0d3df059ec49ab54389861f13310766dfdeb615fed90d |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typing git https://github.com/python/typing.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 24604008 |
| octolytics-dimension-repository_nwo | python/typing |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24604008 |
| octolytics-dimension-repository_network_root_nwo | python/typing |
| 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 | 5bb0fb68d64881d1344f5863d809515d496801e5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width