Skip to content

Commit 08cdbaa

Browse files
committed
Basic fix for ParamSpec with Generic
1 parent 82d512a commit 08cdbaa

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/typing_extensions.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3006,6 +3006,10 @@ def wrapper(*args, **kwargs):
30063006
f"a class or callable, not {arg!r}"
30073007
)
30083008

3009+
def _is_param_expr(arg):
3010+
return arg is ... or isinstance(
3011+
arg, (tuple, list, ParamSpec, _ConcatenateGenericAlias)
3012+
)
30093013

30103014
# We have to do some monkey patching to deal with the dual nature of
30113015
# Unpack/TypeVarTuple:
@@ -3020,6 +3024,18 @@ def _check_generic(cls, parameters, elen=_marker):
30203024
30213025
This gives a nice error message in case of count mismatch.
30223026
"""
3027+
if (inspect.isclass(cls) and issubclass(cls, typing.Generic)
3028+
and any(isinstance(t, ParamSpec) for t in cls.__parameters__)
3029+
):
3030+
# should actually modify parameters but is immutable
3031+
if (
3032+
len(cls.__parameters__) == 1
3033+
and parameters
3034+
and not _is_param_expr(parameters[0])
3035+
):
3036+
assert isinstance(cls.__parameters__[0], ParamSpec)
3037+
return
3038+
30233039
if not elen:
30243040
raise TypeError(f"{cls} is not a generic class")
30253041
if elen is _marker:

0 commit comments

Comments
 (0)