gh-99344, gh-99379, gh-99382: Fix issues in substitution of ParamSpec and TypeVarTuple#99412
Conversation
…ution of ParamSpec and 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.
|
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__, ((),)) | ||
| with self.assertRaises(TypeError): |
There was a problem hiding this comment.
Can you add tests for X[int] and Y[int]? (I guess those should raise TypeError.)
There was a problem hiding this comment.
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.
I don't follow everything going on in typing.py, but I'm sure Serhiy knows what he's doing, and the tests look good.
Thanks, Serhiy!
| for C in Callable, collections.abc.Callable: | ||
| with self.subTest(generic=C): | ||
| A = C[P, Tuple[*Ts]] | ||
| B = A[[int, str], bytes, float] |
There was a problem hiding this comment.
Wow, this is an interesting case. Would it be worth checking C[Tuple[*Ts], P] too?
There was a problem hiding this comment.
C is Callable. Callable[Tuple[*Ts], P] does not make sense. It is an error for collections.abc.Callable, and accepted for typing.Callable (producing a meaningless result), but it is a different issue.
|
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11. |
|
GH-99866 is a backport of this pull request to the 3.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 commit 8f2fb7d) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
|
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 commit 8f2fb7d) 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 commit 8f2fb7d) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Uh oh!
There was an error while loading. Please reload this page.