Title: Fields with single underscore names can mess up dataclasses · Issue #98886 · python/cpython · GitHub
Open Graph Title: Fields with single underscore names can mess up dataclasses · Issue #98886 · python/cpython
X Title: Fields with single underscore names can mess up dataclasses · Issue #98886 · python/cpython
Description: A similar issue to #96151. ericvsmith mentioned this is worth opening an issue for in #98143 (comment) dataclasses uses variables with single underscore names as part of its implementation. This can cause interesting errors, for example:...
Open Graph Description: A similar issue to #96151. ericvsmith mentioned this is worth opening an issue for in #98143 (comment) dataclasses uses variables with single underscore names as part of its implementation. This ca...
X Description: A similar issue to #96151. ericvsmith mentioned this is worth opening an issue for in #98143 (comment) dataclasses uses variables with single underscore names as part of its implementation. This ca...
Opengraph URL: https://github.com/python/cpython/issues/98886
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Fields with single underscore names can mess up dataclasses","articleBody":"A similar issue to https://github.com/python/cpython/issues/96151. ericvsmith mentioned this is worth opening an issue for in https://github.com/python/cpython/pull/98143#issuecomment-1280306360\r\n\r\ndataclasses uses variables with single underscore names as part of its implementation. This can cause interesting errors, for example:\r\n```python\r\nfrom dataclasses import dataclass, field\r\n\r\n@dataclass\r\nclass X:\r\n x: int = field(default_factory=lambda: 111)\r\n _dflt_x: int = field(default_factory=lambda: 222)\r\n\r\nX() # TypeError: '_HAS_DEFAULT_FACTORY_CLASS' object is not callable\r\n```\r\n\r\nThe fix is simple: prefix all of these things with `__dataclass_`, to make name collisions more obviously the user's fault. We already do this for e.g. `__dataclass_self__` in the implementation.\r\n\r\n\u003c!-- gh-linked-prs --\u003e\r\n### Linked PRs\r\n* gh-102032\r\n\u003c!-- /gh-linked-prs --\u003e\r\n","author":{"url":"https://github.com/hauntsaninja","@type":"Person","name":"hauntsaninja"},"datePublished":"2022-10-30T22:48:39.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/98886/cpython/issues/98886"}
| 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:df1d5e4d-1562-1365-515d-bc581e905321 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 80E2:37ACD:3A24196:4FDB16E:6A4F39C8 |
| html-safe-nonce | 237a9df8d7263affdf9c6b2ea82b66b5daf4e12ba382b83b8f805634578fd7f4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MEUyOjM3QUNEOjNBMjQxOTY6NEZEQjE2RTo2QTRGMzlDOCIsInZpc2l0b3JfaWQiOiIxMzY5NzM4ODEyNzcxNDgyMDU2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 1b34e410c3463249f0fabe606509aa10efdfe04541751088a807f878ab8ab891 |
| hovercard-subject-tag | issue:1429044803 |
| 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/98886/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5b8920e1ba3c64e3cf14eedf6cc1182ccfa1a24286d2838a0bcaf617211a95d4/python/cpython/issues/98886 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5b8920e1ba3c64e3cf14eedf6cc1182ccfa1a24286d2838a0bcaf617211a95d4/python/cpython/issues/98886 |
| og:image:alt | A similar issue to #96151. ericvsmith mentioned this is worth opening an issue for in #98143 (comment) dataclasses uses variables with single underscore names as part of its implementation. This ca... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | hauntsaninja |
| hostname | github.com |
| expected-hostname | github.com |
| None | b92d11c0aa4a77d54ef4af1078b6a15fb5a70a215b30c4ecf28889d5a8e656d9 |
| 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 | 4b249b445842943ed31549e027f57a8ade9881ed |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width