Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4865,6 +4865,18 @@ def test_args_kwargs(self):
self.assertEqual(repr(P.args), "P.args")
self.assertEqual(repr(P.kwargs), "P.kwargs")

def test_stringized(self):
P = ParamSpec('P')
class C(Generic[P]):
func: Callable["P", int]
def foo(self, *args: "P.args", **kwargs: "P.kwargs"):
pass

self.assertEqual(gth(C, globals(), locals()), {"func": Callable[P, int]})
self.assertEqual(
gth(C.foo, globals(), locals()), {"args": P.args, "kwargs": P.kwargs}
)

def test_user_generics(self):
T = TypeVar("T")
P = ParamSpec("P")
Expand Down
3 changes: 2 additions & 1 deletion Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ def _type_check(arg, msg, is_argument=True, module=None, *, allow_special_forms=
return arg
if isinstance(arg, _SpecialForm) or arg in (Generic, Protocol):
raise TypeError(f"Plain {arg} is not valid as type argument")
if isinstance(arg, (type, TypeVar, ForwardRef, types.UnionType, ParamSpec)):
if isinstance(arg, (type, TypeVar, ForwardRef, types.UnionType, ParamSpec,
ParamSpecArgs, ParamSpecKwargs)):
return arg
if not callable(arg):
raise TypeError(f"{msg} Got {arg!r:.100}.")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
In :func:`typing.get_type_hints`, support evaluating stringified ``ParamSpecArgs`` and ``ParamSpecKwargs`` annotations. Patch by Gregory Beauregard.