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

gh-99344, gh-99379, gh-99382: Fix issues in substitution of ParamSpec and TypeVarTuple#99412

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

Conversation

@serhiy-storchaka
Copy link
Member

@serhiy-storchakaserhiy-storchaka commentedNov 12, 2022
edited
Loading

  • Fix substitution of TypeVarTuple and ParamSpec together in user generics.
  • Fix substitution of ParamSpec followed by TypeVarTuple in generic aliases.
  • Check the number of arguments in substitution in user generics containing a TypeVarTuple and one or more TypeVar.

…ution of ParamSpecand TypeVarTuple* Fix substitution of TypeVarTuple and ParamSpec together in user generics.* Fix substitution of ParamSpec followed by TypeVarTuple in generic aliases.* Check the number of arguments in substitution in user generics containing a  TypeVarTuple and one or more TypeVar.
@gvanrossum
Copy link
Member

I'm not sure I'm the one to review this. Maybe@mrahtz can follow this?

TheBakerCat reacted with laugh emoji

self.assertEqual(G3.__args__, ((bytes,),))
G4=X[[]]
self.assertEqual(G4.__args__, ((),))
withself.assertRaises(TypeError):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Can you add tests forX[int] andY[int]? (I guess those should raise TypeError.)

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

No, unfortunately it does not raise TypeError. The type check for ParamSpec and TypeVar substitution are too lenient and accept any nonsense.

>>> from typing import *>>> T = TypeVar('T')>>> P = ParamSpec('P')>>> class A(Generic[P, T]): pass... >>> A[int, [str]]__main__.A[int, [<class 'str'>]]>>> A[1, 2]__main__.A[1, 2]

More strict type checks can be introduced in a separate issue.

Copy link
Contributor

@mrahtzmrahtz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I don't follow everything going on intyping.py, but I'm sure Serhiy knows what he's doing, and the tests look good.

Thanks, Serhiy!

forCinCallable,collections.abc.Callable:
withself.subTest(generic=C):
A=C[P,Tuple[*Ts]]
B=A[[int,str],bytes,float]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Wow, this is an interesting case. Would it be worth checkingC[Tuple[*Ts], P] too?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

C isCallable.Callable[Tuple[*Ts], P] does not make sense. It is an error forcollections.abc.Callable, and accepted fortyping.Callable (producing a meaningless result), but it is a different issue.

@serhiy-storchakaserhiy-storchaka merged commit8f2fb7d intopython:mainNov 29, 2022
@miss-islington
Copy link
Contributor

Thanks@serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

@serhiy-storchakaserhiy-storchaka deleted the typing-paramspec-subst branchNovember 29, 2022 07:46
@bedevere-bot
Copy link

GH-99866 is a backport of this pull request to the3.11 branch.

@bedevere-botbedevere-bot removed the needs backport to 3.11only security fixes labelNov 29, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestNov 29, 2022
…ution of ParamSpec and TypeVarTuple (pythonGH-99412)* Fix substitution of TypeVarTuple and ParamSpec together in user generics.* Fix substitution of ParamSpec followed by TypeVarTuple in generic aliases.* Check the number of arguments in substitution in user generics containing a  TypeVarTuple and one or more TypeVar.(cherry picked from commit8f2fb7d)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@AlexWaygoodAlexWaygood added the needs backport to 3.11only security fixes labelNov 29, 2022
@miss-islington
Copy link
Contributor

Thanks@serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestNov 29, 2022
…ution of ParamSpec and TypeVarTuple (pythonGH-99412)* Fix substitution of TypeVarTuple and ParamSpec together in user generics.* Fix substitution of ParamSpec followed by TypeVarTuple in generic aliases.* Check the number of arguments in substitution in user generics containing a  TypeVarTuple and one or more TypeVar.(cherry picked from commit8f2fb7d)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@AlexWaygoodAlexWaygood removed the needs backport to 3.11only security fixes labelNov 29, 2022
miss-islington added a commit that referenced this pull requestNov 29, 2022
… and TypeVarTuple (GH-99412)* Fix substitution of TypeVarTuple and ParamSpec together in user generics.* Fix substitution of ParamSpec followed by TypeVarTuple in generic aliases.* Check the number of arguments in substitution in user generics containing a  TypeVarTuple and one or more TypeVar.(cherry picked from commit8f2fb7d)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@JelleZijlstraJelleZijlstraJelleZijlstra left review comments

@gvanrossumgvanrossumAwaiting requested review from gvanrossum

@Fidget-SpinnerFidget-SpinnerAwaiting requested review from Fidget-Spinner

@AlexWaygoodAlexWaygoodAwaiting requested review from AlexWaygoodAlexWaygood is a code owner

+1 more reviewer

@mrahtzmrahtzmrahtz approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

7 participants

@serhiy-storchaka@gvanrossum@miss-islington@bedevere-bot@JelleZijlstra@mrahtz@AlexWaygood

[8]ページ先頭

©2009-2025 Movatter.jp