You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I create generic class with specifying __init__ arguments through ParamSpec:
from typing import Generic
from typing_extensions import ParamSpec
P = ParamSpec('P')
class CLS(Generic[P]):
def __init__(self, *args: P.args, **kwargs: P.kwargs):
...
class ONE(CLS[int]):
...
class TWO(CLS[int, int]):
...
# should pass type checks:
ONE(1)
TWO(1, 2)
# should fail type checks:
ONE(1, 2)
TWO(1)
mypy type checking works as expected, but during runtime I got next error:
Traceback (most recent call last):
File "temp/issue.py", line 13, in <module>
class TWO(CLS[int, int]):
File "/usr/local/Cellar/python@3.9/3.9.16/Frameworks/Python.framework/Versions/3.9/lib/python3.9/typing.py", line 277, in inner
return func(*args, **kwds)
File "/usr/local/Cellar/python@3.9/3.9.16/Frameworks/Python.framework/Versions/3.9/lib/python3.9/typing.py", line 1004, in __class_getitem__
_check_generic(cls, params, len(cls.__parameters__))
File "/usr/local/lib/python3.9/site-packages/typing_extensions.py", line 109, in _check_generic
raise TypeError(f"Too {'many' if alen > elen else 'few'} parameters for {cls};"
TypeError: Too many parameters for <class '__main__.CLS'>; actual 2, expected 1
Is it a bug? It works fine in 3.10 and 3.11
The text was updated successfully, but these errors were encountered:
I believe this is covered by the note in the README that says "Certain PEP 612 special cases in user-defined Generics are also not available." We could create a typing_extensions.Generic to add support for this though, if we can't hack it into typing.Generic.
I create generic class with specifying
__init__
arguments through ParamSpec:mypy type checking works as expected, but during runtime I got next error:
Is it a bug? It works fine in 3.10 and 3.11
The text was updated successfully, but these errors were encountered: