Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3.1k
Allow TypedDict unpacking in Callable types#16083
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Diff frommypy_primer, showing the effect of this PR on open source code: graphql-core (https://github.com/graphql-python/graphql-core): typechecking got 1.06x slower (313.1s -> 331.1s)(Performance measurements are based on a single noisy sample) |
JelleZijlstra commentedSep 10, 2023
So to be clear this allows |
ilevkivskyi commentedSep 11, 2023
@JelleZijlstra I don't like the model where people outside of mypy have to say anything about whether a given feature should be in mypy or not. We can coordinate on details of semantics of certain constructs, to achieve better compatibility (especially for use in typeshed), but this doesn't really apply here, since semantics is quite obvious. |
tmke8 commentedSep 12, 2023
This idea could even be extended to P=ParamSpec("P")classC(Generic[P]):def__init__(self,f:Callable[P,None]): ...classArgs(TypedDict):x:inty:strdeff(*,x:int,y:str)->None: ...c:C[[Unpack[Args]]]=C(f)# OKd:C[[int,str]]==C(f)# error because `f` expects keyword arguments? |
ilevkivskyi commentedSep 12, 2023
@tmke8 Yes, this is totally possible. It however may be a bit trickier to implement (and I am busy with other things now). You can open a separate issue for this. |
Fixes#16082
Currently we only allow
Unpackof a TypedDict when it appears in a function definition. This PR also allows this inCallabletypes, similarly to how we do this for variadic types.Note this still doesn't allow having both variadic unpack and a TypedDict unpack in the same
Callable. Supporting this is tricky, so let's not so this until people will actually ask for this. FWIW we can always suggest callback protocols for such tricky cases.