Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
ilevkivskyi merged 1 commit intopython:masterfromilevkivskyi:fix-unpack-callable
Sep 11, 2023

Conversation

@ilevkivskyi
Copy link
Member

Fixes#16082

Currently we only allowUnpack of a TypedDict when it appears in a function definition. This PR also allows this inCallable types, 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 sameCallable. 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.

shadycuz and tmke8 reacted with thumbs up emojishadycuz reacted with hooray emoji
@github-actions
Copy link
Contributor

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
Copy link
Member

So to be clear this allowsCallable[[Unpack[TD]], T], whereTD is a TypedDict. It's pretty obvious what that means, but I don't think any PEP prescribes it (PEP 692 says nothing aboutCallable[]), so I'm uncomfortable adding this to mypy without further discussion and buy-in from other type checkers.

@ilevkivskyi
Copy link
MemberAuthor

@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.

@ilevkivskyiilevkivskyi merged commit9e520c3 intopython:masterSep 11, 2023
@ilevkivskyiilevkivskyi deleted the fix-unpack-callable branchSeptember 11, 2023 19:02
@tmke8
Copy link
Contributor

This idea could even be extended toParamSpec:

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
Copy link
MemberAuthor

@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.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@hauntsaninjahauntsaninjahauntsaninja approved these changes

@JelleZijlstraJelleZijlstraAwaiting requested review from JelleZijlstra

@JukkaLJukkaLAwaiting requested review from JukkaL

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Unable to use Unpack inside a Callable

4 participants

@ilevkivskyi@JelleZijlstra@tmke8@hauntsaninja

[8]ページ先頭

©2009-2025 Movatter.jp