-
-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PEP 692 -- Using TypedDict for more precise **kwargs typing #140
Comments
Jelle and I are debating who should write the summary of the typing-sig discussion. |
Jelle and I support this PEP. It has several moving parts: a grammar change, a new dunder, a new special in typing.py, and of course implementations in type checkers. However, almost the only thing that users will see is a small piece of new grammar: class Movie(TypedDict):
title: str
year: int
def foo(arg1: type1, **kwds: **Movie) -> type2:
... Or the pre-3.12 equivalent using from typing_extensions import Unpack
def foo(arg1: type1, **kwds: Unpack[Movie]) -> type2:
... (The dunder exists solely to be able to implement The main objection brought in on Discourse, also heard on typing-sig, is that the use case is a bit weak: why would you write the above def foo(arg1: type1, *, title: str, year: int) -> type2:
... The answer is that if you're writing new code, you probably would write it that way, but if you're adding type annotations to a large code base that happens to use this pattern (for whatever reason) it would require an unreasonable amount of refactoring to do everything "right", and this syntax is a pretty good way to get such functions to be fully annotated (including type checking of individual keyword types, rejection of unknown keywords, and requiring certain keywords). The typing-sig discussion helped the author firm up the design and the text of the PEP in various ways, and we're happy with the result. Note that the feature is already implemented in mypy and a prototype implementation also exists in pyright. The other type checkers will be able to quickly follow this lead, should the PEP be accepted. |
This is my sentiment as well. Very glad to have the new It feels odd to me that we can type hint Something like |
The SC tracker is not the place to have this discussion. Note that my post here was to satisfy th SC’s requirement from the checklist above. |
Apologies. |
Clarify Guido/Jelle's comment on typing PEPs should just be a quick confirmation. The PEP itself should include the kind of [summary we got for PEP 692](#140 (comment)). *(This is a proposal from me to the SC.)*
Thanks! I added this to the SC agenda. @gvanrossum, I see the word summary in the template is misleading -- what I was imagining to get from you is more of a quick confirmation/pronouncement that the PEP captures the typing-sig discussions/consensus, so the SC doesn't need to go through the archives, and we can consider it approved by “typing-sig as a whole”. The discussions should ideally be summarized in the PEP itself, rather than the SC ticket. I'll get that clarified. @adam-grant-hendry, the place to discuss the PEP is linked in its |
Clarify Guido/Jelle's comment on typing PEPs should just be a quick confirmation. The PEP itself should include the kind of [summary we got for PEP 692](#140 (comment)).
Left a comment on behalf of the SC at https://discuss.python.org/t/pep-692-using-typeddict-for-more-precise-kwargs-typing/17314/52 . |
@gvanrossum now that the PEP has been updated to not have the syntax change, are you up for being the PEP delegate? We wanted to make sure you are still happy with the PEP even w/o the syntax. |
Guido just said elsewhere that he'll be mostly absent for a little while, FYI. However, https://discuss.python.org/t/pep-692-using-typeddict-for-more-precise-kwargs-typing/17314/70?u=jelle suggests he's OK with accepting the PEP without the syntax change. He did not review the PEP change (python/peps#2941). |
What Jelle said. I'm okay with accepting this PEP (though I still would have preferred it with the syntax change). |
The SC is happy to say the sans-syntax version of the PEP is accepted! |
@franekmagiera or @JelleZijlstra, please could you update the PEP to mark it as accepted? |
Thanks, opened python/peps#3022 |
Please consider PEP 692 -- Using TypedDict for more precise **kwargs typing
https://peps.python.org/pep-0692/
Post-History
headerPost-History
)SIG-specific:
The text was updated successfully, but these errors were encountered: