Skip to content

Commit d314b67

Browse files
committed
Update node checks to be more type specific and rename typ to argtyp
1 parent c8ae0e9 commit d314b67

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

mypy/checkexpr.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -551,31 +551,33 @@ def visit_call_expr_inner(self, e: CallExpr, allow_none_return: bool = False) ->
551551
):
552552
# Special hanlding for get_args(), returns a typed tuple
553553
# with the type set by the input
554-
typ = None
554+
argtyp = None
555555
if isinstance(e.args[0], IndexExpr):
556556
self.accept(e.args[0].index)
557-
typ = self.chk.lookup_type(e.args[0].index)
558-
else:
557+
argtyp = self.chk.lookup_type(e.args[0].index)
558+
elif isinstance(e.args[0], NameExpr):
559559
try:
560560
node = self.chk.lookup_qualified(e.args[0].name)
561561
if node:
562562
if isinstance(node.node, TypeAlias):
563563
# Resolve type
564-
typ = get_proper_type(node.node.target)
565-
else:
566-
typ = node.node.type
564+
argtyp = node.node.target
565+
elif isinstance(node.node, Var):
566+
argtyp = node.node.type
567567
except KeyError:
568568
# Undefined names should already be reported in semantic analysis.
569569
pass
570+
if argtyp is not None:
571+
argtyp = get_proper_type(argtyp)
570572
if (
571-
typ is not None
572-
and isinstance(typ, UnionType)
573-
and all(isinstance(t, LiteralType) for t in typ.items)
573+
argtyp is not None
574+
and isinstance(argtyp, UnionType)
575+
and all(isinstance(get_proper_type(t), LiteralType) for t in argtyp.items)
574576
):
575577
# Returning strings is defined but order isn't so
576578
# we need to return type * len of the union
577579
return TupleType(
578-
[typ] * len(typ.items), fallback=self.named_type("builtins.tuple")
580+
[argtyp] * len(argtyp.items), fallback=self.named_type("builtins.tuple")
579581
)
580582
else:
581583
# Fall back to what we did anyway (Tuple[Any])

0 commit comments

Comments
 (0)