Title: Add a Dataclass abstract base class for instance checking and type annotations · Issue #102699 · python/cpython · GitHub
Open Graph Title: Add a Dataclass abstract base class for instance checking and type annotations · Issue #102699 · python/cpython
X Title: Add a Dataclass abstract base class for instance checking and type annotations · Issue #102699 · python/cpython
Description: Feature or enhancement Add the class dataclasses.Dataclass that supports instance and subclass checks using similar logic as dataclasses.is_dataclass, and blocks inheritance in __init_subclass__. (Edit: removed "has an attribute __datacl...
Open Graph Description: Feature or enhancement Add the class dataclasses.Dataclass that supports instance and subclass checks using similar logic as dataclasses.is_dataclass, and blocks inheritance in __init_subclass__. (...
X Description: Feature or enhancement Add the class dataclasses.Dataclass that supports instance and subclass checks using similar logic as dataclasses.is_dataclass, and blocks inheritance in __init_subclass__. (...
Opengraph URL: https://github.com/python/cpython/issues/102699
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add a Dataclass abstract base class for instance checking and type annotations","articleBody":"# Feature or enhancement\r\n\r\nAdd the class `dataclasses.Dataclass` that\r\n- supports instance and subclass checks using similar logic as `dataclasses.is_dataclass`, and\r\n- blocks inheritance in `__init_subclass__`.\r\n\r\n(Edit: removed \"has an attribute `__dataclass_fields__` for the purpose of type checking\")\r\n\r\n# Pitch\r\n\r\nThis class would simplify runtime type-checking of dataclasses:\r\n```python\r\nnot isinstance(x, type) and dataclasses.is_dataclass(x) # Previously\r\nisinstance(x, dataclasses.Dataclass) # With this feature.\r\n```\r\nand similarly\r\n```python\r\nisinstance(x, type) and dataclasses.is_dataclass(x) # Previously.\r\nissubclass(x, dataclasses.Dataclass) # With this feature.\r\n```\r\nBesides being simpler, it would also allow combined instance checks like `isinstance(x, Dataclass | SomeOtherBase)`, which is arguably more Pythonic than the combined function calls above (marked \"Previously\").\r\n\r\nIt would also allow users to annotate dataclasses using `Dataclass` or `type[Dataclass]`, which is currently impossible without reaching into protected areas of the typeshed.\r\n\r\nInheritance could be blocked for now with a friendly error message (that perhaps tells you to use the decorator either directly or in a base class's `__init_subclass__`).\r\n\r\n# Previous discussion\r\n\r\nThere's some discussion here: https://github.com/python/typing_extensions/issues/115\r\n@AlexWaygood \r\n@JelleZijlstra \r\n@henryiii \n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-102933\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/NeilGirdhar","@type":"Person","name":"NeilGirdhar"},"datePublished":"2023-03-14T20:03:22Z","url":"https://github.com/python/cpython/issues/102699"}
| 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:ae93dbc9-2132-eb75-4770-dd431f4e039c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BFEC:7B930:65EA9C:8B5808:6B0077B1 |
| html-safe-nonce | b71fc3a458f29779f6d3cf12a4262021c4666cfb52fee4254fca85968fcf07dd |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRkVDOjdCOTMwOjY1RUE5Qzo4QjU4MDg6NkIwMDc3QjEiLCJ2aXNpdG9yX2lkIjoiODQ3MjQyMTY2MDA1NjY0NzYwMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c4aaacfa4a7fee03edb5a3cf3189fc9c4522e06d1c47a314d062cee13b1a4f80 |
| hovercard-subject-tag | issue:1624215692 |
| 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/102699/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8acc02b2b14a24739bfbef2fcf4dc882d172795ed1d2c46743a319a09be3607e/python/cpython/issues/102699 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8acc02b2b14a24739bfbef2fcf4dc882d172795ed1d2c46743a319a09be3607e/python/cpython/issues/102699 |
| og:image:alt | Feature or enhancement Add the class dataclasses.Dataclass that supports instance and subclass checks using similar logic as dataclasses.is_dataclass, and blocks inheritance in __init_subclass__. (... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | NeilGirdhar |
| hostname | github.com |
| expected-hostname | github.com |
| None | 75c2b65dd205f26961d0c29afed1a8d0bb7cca9f05780571dfd1ef93eb539d16 |
| 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 | 84e563eb4b55f8fa102f325f117533cee9e3df4a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width