diff options
author | Nikita Sobolev <mail@sobolevn.me> | 2023-01-23 07:52:58 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-23 07:52:58 (GMT) |
commit | 807d6b576fa37f3ab7eb951297cb365c0c198595 (patch) | |
tree | fc498ab1ba2db515d3528d52050180ee77aead6c /Lib/typing.py | |
parent | d717be04dc7876696cb21ce7901bda0214c4b2e0 (diff) | |
download | cpython-807d6b576fa37f3ab7eb951297cb365c0c198595.zip cpython-807d6b576fa37f3ab7eb951297cb365c0c198595.tar.gz cpython-807d6b576fa37f3ab7eb951297cb365c0c198595.tar.bz2 |
gh-101015: Fix `typing.get_type_hints` with unpacked `*tuple` (PEP 646) (#101031)
Diffstat (limited to 'Lib/typing.py')
-rw-r--r-- | Lib/typing.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/Lib/typing.py b/Lib/typing.py index 4675af1..bdf51bb 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -371,10 +371,13 @@ def _eval_type(t, globalns, localns, recursive_guard=frozenset()): ForwardRef(arg) if isinstance(arg, str) else arg for arg in t.__args__ ) + is_unpacked = t.__unpacked__ if _should_unflatten_callable_args(t, args): t = t.__origin__[(args[:-1], args[-1])] else: t = t.__origin__[args] + if is_unpacked: + t = Unpack[t] ev_args = tuple(_eval_type(a, globalns, localns, recursive_guard) for a in t.__args__) if ev_args == t.__args__: return t @@ -828,7 +831,7 @@ class ForwardRef(_Final, _root=True): # Unfortunately, this isn't a valid expression on its own, so we # do the unpacking manually. if arg[0] == '*': - arg_to_compile = f'({arg},)[0]' # E.g. (*Ts,)[0] + arg_to_compile = f'({arg},)[0]' # E.g. (*Ts,)[0] or (*tuple[int, int],)[0] else: arg_to_compile = arg try: |