Do not recurse into `Literal` arguments during type evaluation (#156534)
Unlike other generic aliases, `Literal` arguments aren't type expressions
(e.g. `Literal[1, 'a'].__args__ == (1, 'a')`. As such, there is no need
to recurse into all the arguments as they are guaranteed to be returned
unchanged.
diff --git a/Lib/typing.py b/Lib/typing.py
index 65e1d1e..99c467a 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -475,6 +475,9 @@ def _eval_type(t, globalns, localns, type_params, *, recursive_guard=frozenset()
type_params=type_params, owner=owner,
_recursive_guard=recursive_guard, format=format)
if isinstance(t, (_GenericAlias, GenericAlias, Union)):
+ if isinstance(t, _LiteralGenericAlias):
+ # Unlike other generic aliases, Literal arguments aren't type expressions
+ return t
if isinstance(t, GenericAlias):
args = tuple(
_make_forward_ref(arg, parent_fwdref=parent_fwdref) if isinstance(arg, str) else arg