Ken Jin <kenjin4...@gmail.com> added the comment:

> and was surprised that C.__parameters__ was (T,) instead of (T, P).
Alright, I just fixed that :).

I'm now encountering many problems with how typing works which prevent what PEP 
612 declare as valid from not throwing an error (these are all examples copied 
from the PEP)::

class X(Generic[T, P]): ...

1. X[int, [int, bool]] raises TypeError because second arg isn't a type (this 
is easy to fix).

2. X[int, ...] raises TypeError because for the same reason. One way to fix 
this is to automatically convert Ellipsis to EllipsisType just like how we 
already convert None to NoneType. Only problem now is that Callable[[...], int] 
doesn't raise TypeError. Should we just defer the problem of validating 
Callable to static type checkers instead?

class Z(Generic[P]): ...

3. Z[[int, str, bool]] raises TypeError, same as 1.

4. Z[int, str, bool] raises TypeError, but for too many parameters (not enough 
TypeVars). This one troubles me the most, current TypeVar substitution checks 
for len(__args__) == len(__parameters__).


I have a feeling your wish of greatly loosening type checks will come true ;). 
Should we proceed with that? That'd fix 1, 2, 3. The only showstopper now is 4. 
A quick idea is to just disable the check for len(__args__) == 
len(__parameters__) if there's only a single ParamSpec in __parameters__.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue41559>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to