Update unpack TypedDict kwargs forwarding spec + add conformance tests - #2338
Update unpack TypedDict kwargs forwarding spec + add conformance tests#2338yangdanny97 wants to merge 7 commits into
Conversation
|
This issue is nuanced, because many unpacking behaviors in Python are unsafe. If you unpack a In ty we made the decision not to error on the first case here, because we saw large mypy-primer fallout if we enforced this rule, and we felt it was analogous to the case of We decided to be stricter with I think ty's compromise is reasonable, but I'm not totally convinced it's the best option, open to other resolutions here. But enforcing this rule on all implicitly open TypedDicts will have a significant impact on existing real-world code. |
|
For Pyrefly my current thought is that this would be off-by-default and enabled in strict mode. |
|
That seems reasonable. I'm not sure if behavior that we wouldn't turn on by default in our own type checkers should be encoded as a conformance suite requirement, though? It seems to me that a strict mode which requires safety in unpacking an open TypedDict should probably also require safety in unpacking a list/Sequence? |
|
So do you think that we should just merge #1960 and delete this section from the typing spec entirely? Or weaken the first assertion to "may" and "E?" |
|
I would probably land this with the first assertion weakened (and discussion of that in the spec also), but that's not a strong preference, it just matches what we decided to do in ty, so naturally it already makes sense to me :) Very open to other opinions here. |
…ypedDicts optional
|
Does it make sense to differentiate between implicitly open and explicitly open ( |
It might. Currently in ty we only apply the extra strictness with |
|
The current TypedDict spec says that In the abstract I'd prefer to treat open TypedDicts similar to ones with |
carljm
left a comment
There was a problem hiding this comment.
I think there are a couple details here in the spec (one backwards statement, one broken link) that should be addressed -- everything else here is up to you whether you want to include it in this PR. Otherwise this looks ready to me.
I'm glad we are clearing this up now, before wider adoption of closed/extra_items TypedDicts.
carljm
left a comment
There was a problem hiding this comment.
I'm happy with this.
I guess since it touches the spec and the conformance suite, we need a Discuss thread, the one-week wait, and an issue for Typing Council sign-off?
Previously, this section of the spec was not exercised at all in the conformance tests, and also was not implemented by any type checker.
This PR updates the spec to account for closed & extra_items TypedDicts, and adds conformance tests.
There are 3 asserted errors:
This would supersede #1960, which proposed that we delete the section of the spec entirely.
@rchen152's comment in https://discuss.python.org/t/typing-spec-inconsistency-for-unpacking-typed-dict-kwargs/79640 favors deletion.