Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
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
gh-99344, gh-99379, gh-99382: Fix issues in substitution of ParamSpec and TypeVarTuple#99412
Uh oh!
There was an error while loading.Please reload this page.
Conversation
…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 commentedNov 14, 2022
I'm not sure I'm the one to review this. Maybe@mrahtz can follow this? |
| self.assertEqual(G3.__args__, ((bytes,),)) | ||
| G4=X[[]] | ||
| self.assertEqual(G4.__args__, ((),)) | ||
| withself.assertRaises(TypeError): |
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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.
mrahtz left a comment
There was a problem hiding this 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] |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
miss-islington commentedNov 29, 2022
Thanks@serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11. |
bedevere-bot commentedNov 29, 2022
GH-99866 is a backport of this pull request to the3.11 branch. |
…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>
miss-islington commentedNov 29, 2022
Thanks@serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11. |
…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>
… 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>
Uh oh!
There was an error while loading.Please reload this page.