bpo-46643: Fix stringized P.args/P.kwargs with get_type_hints (GH-31238)

(cherry picked from commit 75d2d945b4)

Co-authored-by: Gregory Beauregard <greg@greg.red>
This commit is contained in:
Miss Islington (bot) 2022-03-02 18:26:50 -08:00 committed by GitHub
parent 60b561c246
commit 257f5be7f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 1 deletions

View file

@ -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}.")