diff options
author | Niklas Rosenstein <rosensteinniklas@gmail.com> | 2022-03-07 18:02:59 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-07 18:02:59 (GMT) |
commit | b465b606049f6f7dd0711cb031fdaa251818741a (patch) | |
tree | 6f7400938ba0ed3d7b19ffdfe834135e0eaa8575 /Lib/typing.py | |
parent | 77446d2aa56e9e3262d9d2247342bbbb0ff5e907 (diff) | |
download | cpython-b465b606049f6f7dd0711cb031fdaa251818741a.zip cpython-b465b606049f6f7dd0711cb031fdaa251818741a.tar.gz cpython-b465b606049f6f7dd0711cb031fdaa251818741a.tar.bz2 |
bpo-41370: Evaluate strings as forward refs in PEP 585 generics (GH-30900)
This removes discrepancy between list["int"] and List["int"].
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Diffstat (limited to 'Lib/typing.py')
-rw-r--r-- | Lib/typing.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/typing.py b/Lib/typing.py index 27d83c5..360129e 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -336,6 +336,12 @@ def _eval_type(t, globalns, localns, recursive_guard=frozenset()): if isinstance(t, ForwardRef): return t._evaluate(globalns, localns, recursive_guard) if isinstance(t, (_GenericAlias, GenericAlias, types.UnionType)): + if isinstance(t, GenericAlias): + args = tuple( + ForwardRef(arg) if isinstance(arg, str) else arg + for arg in t.__args__ + ) + t = t.__origin__[args] ev_args = tuple(_eval_type(a, globalns, localns, recursive_guard) for a in t.__args__) if ev_args == t.__args__: return t |