Title: conformance: allow consistent treatment of kwargs: Unpack[TD] by carljm · Pull Request #2272 · python/typing · GitHub
Open Graph Title: conformance: allow consistent treatment of kwargs: Unpack[TD] by carljm · Pull Request #2272 · python/typing
X Title: conformance: allow consistent treatment of kwargs: Unpack[TD] by carljm · Pull Request #2272 · python/typing
Description: The conformance suite currently asserts this (simplified for clarity): class TD(TypedDict): v1: int def f(**kwargs: Unpack[TD]): ... f(v1=1, v2=2) # E: TD doesn't contain `v2` This implies that the signature of f de-sugars to f(*, v1: int). But the current conformance suite simultaneously also requires that callable assignability behave as if it de-sugars to f(*, v1: int, **kwargs: object). That addition to the conformance suite was justified by this call, which is allowed by pyright and pyrefly: class TD2(TD1): v2: int def _(td2: TD2): f(**td2) It seems reasonable to allow this call, because TD2 is a subtype of TD1 and assignable to it, so **td2 should therefore be acceptable for **kwargs: Unpack[TD1]. But if this call (which definitely provides a keyword argument v2) is allowed, then we should also allow the above call that explicitly provides v2. I think we could defensibly pick either of the interpretations of the signature of f (with or without **kwargs: object), but type checkers should be allowed to pick a consistent interpretation, not be required to implement an inconsistent hybrid behavior. The interpretation with **kwargs: object is IMO more consistent and better supported by the spec. The spec says that if TD has extra_items, then arbitrary additional keyword arguments of that type should be accepted. And it also says that a TypedDict without an explicit closed or extra_items parameter usually behaves as if it has extra_items of type ReadOnly[object]. The interpretation without **kwargs: object would effectively be saying that **kwargs: Unpack[TD] is one of these special cases (along with TypedDict constructor calls) where an unmarked TypedDict is (inconsistent with its "open" semantics) not treated as having extra_items of type ReadOnly[object]. We can have a discussion about which of these interpretations should be preferred, but given the lack of clarity about this in the spec, I think for now a conformant implementation should be allowed to choose either interpretation and implement it consistently.
Open Graph Description: The conformance suite currently asserts this (simplified for clarity): class TD(TypedDict): v1: int def f(**kwargs: Unpack[TD]): ... f(v1=1, v2=2) # E: TD doesn't contain `v2` This implies t...
X Description: The conformance suite currently asserts this (simplified for clarity): class TD(TypedDict): v1: int def f(**kwargs: Unpack[TD]): ... f(v1=1, v2=2) # E: TD doesn't contain `v2` This impli...
Opengraph URL: https://github.com/python/typing/pull/2272
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:d5b8af6a-5a1f-4d53-d08a-8c2034347172 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | ED9C:37E442:1BFB9F:244084:6AFF93A2 |
| html-safe-nonce | 4c3ccdad899c471f35d1d715e98cfc9c1dd0ad39d8c502189d21cca7855389c0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFRDlDOjM3RTQ0MjoxQkZCOUY6MjQ0MDg0OjZBRkY5M0EyIiwidmlzaXRvcl9pZCI6IjM1NTEyMDcyMjcwMzEyNjIxMTQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 0685a3017eae7dfbc835a37cffe98cc43b26d26557eedd498717ec800b3b00a2 |
| hovercard-subject-tag | pull_request:3570277611 |
| 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/typing/pull/2272/files |
| twitter:image | https://avatars.githubusercontent.com/u/61586?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/61586?s=400&v=4 |
| og:image:alt | The conformance suite currently asserts this (simplified for clarity): class TD(TypedDict): v1: int def f(**kwargs: Unpack[TD]): ... f(v1=1, v2=2) # E: TD doesn't contain `v2` This implies t... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 2c75d045e8c84b51e2ac680086a6dd1eeaf2bc15b82137d22ee5106835d6256c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| 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 full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | aa486b0389431f870c0adf9d4758aaff807c2d97 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width