Title: Use enum trick for dataclasses.MISSING by sirosen · Pull Request #7127 · python/typeshed · GitHub
Open Graph Title: Use enum trick for dataclasses.MISSING by sirosen · Pull Request #7127 · python/typeshed
X Title: Use enum trick for dataclasses.MISSING by sirosen · Pull Request #7127 · python/typeshed
Description: The goal of this change is to fix the behavior of dataclasses.Field. Several attributes of a Field may have a value of MISSING (a sentinel value). As a result, attributes of Field may be checked against MISSING as in [f for f in fields(obj) if f.default is MISSING] default, default_factory, and kw_only are the attributes which may have a value of MISSING. This workaround of defining _MISSING_TYPE as an enum, and MISSING as its only member, allows ... | Literal[MISSING] to be used in type annotations for these attributes. This is very slightly inaccurate -- primarily in that _MISSING_TYPE isn't really an enum -- but this allows for use in Literal. After PEP 661 (Sentinel Values), there may be a more accurate way of writing this, but for now this works. This adjustment is only applied to the attributes of Field, not the arguments to functions and methods. There have been two previous attempts to handle this, #5900 and #7126. Per those PRs, PEP 661 (Sentinel Values) will provide the best solution for this in the future. The enum+Literal workaround used here was suggested as a way to handle dataclasses.MISSING while we wait for that PEP.
Open Graph Description: The goal of this change is to fix the behavior of dataclasses.Field. Several attributes of a Field may have a value of MISSING (a sentinel value). As a result, attributes of Field may be checked ag...
X Description: The goal of this change is to fix the behavior of dataclasses.Field. Several attributes of a Field may have a value of MISSING (a sentinel value). As a result, attributes of Field may be checked ag...
Opengraph URL: https://github.com/python/typeshed/pull/7127
X: @github
Domain: github.com
| 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 | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:e7cbbac7-9d3c-f4fd-1731-e8009b2306c1 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | AC74:1A2F85:360BBF:48F94C:6B002887 |
| html-safe-nonce | d11536fe24191b7b7ef54f68cc1da262735c246b5f8c45a47d7f26c843ea138b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQzc0OjFBMkY4NTozNjBCQkY6NDhGOTRDOjZCMDAyODg3IiwidmlzaXRvcl9pZCI6IjI1ODE2ODI0Nzk1MjYwNjIyMTUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 8dc3d4ef36738cf4858f181c9cc1268713bd5f3328a630fc0b5d5a47e3ff52b7 |
| hovercard-subject-tag | pull_request:839968962 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/python/typeshed/pull/7127/files |
| twitter:image | https://avatars.githubusercontent.com/u/1300022?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/1300022?s=400&v=4 |
| og:image:alt | The goal of this change is to fix the behavior of dataclasses.Field. Several attributes of a Field may have a value of MISSING (a sentinel value). As a result, attributes of Field may be checked ag... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python/typeshed git https://github.com/python/typeshed.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 31696383 |
| octolytics-dimension-repository_nwo | python/typeshed |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 31696383 |
| octolytics-dimension-repository_network_root_nwo | python/typeshed |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 44c658b24abf00491fb7ae5f56d42c9f38cbeab2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width