Skip to content

Commit

Permalink
Update node checks to be more type specific and rename typ to argtyp
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordandev678 committed Sep 18, 2024
1 parent c8ae0e9 commit d314b67
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,31 +551,33 @@ def visit_call_expr_inner(self, e: CallExpr, allow_none_return: bool = False) ->
):
# Special hanlding for get_args(), returns a typed tuple
# with the type set by the input
typ = None
argtyp = None
if isinstance(e.args[0], IndexExpr):
self.accept(e.args[0].index)
typ = self.chk.lookup_type(e.args[0].index)
else:
argtyp = self.chk.lookup_type(e.args[0].index)
elif isinstance(e.args[0], NameExpr):
try:
node = self.chk.lookup_qualified(e.args[0].name)
if node:
if isinstance(node.node, TypeAlias):
# Resolve type
typ = get_proper_type(node.node.target)
else:
typ = node.node.type
argtyp = node.node.target
elif isinstance(node.node, Var):
argtyp = node.node.type
except KeyError:
# Undefined names should already be reported in semantic analysis.
pass
if argtyp is not None:
argtyp = get_proper_type(argtyp)
if (
typ is not None
and isinstance(typ, UnionType)
and all(isinstance(t, LiteralType) for t in typ.items)
argtyp is not None
and isinstance(argtyp, UnionType)
and all(isinstance(get_proper_type(t), LiteralType) for t in argtyp.items)
):
# Returning strings is defined but order isn't so
# we need to return type * len of the union
return TupleType(
[typ] * len(typ.items), fallback=self.named_type("builtins.tuple")
[argtyp] * len(argtyp.items), fallback=self.named_type("builtins.tuple")
)
else:
# Fall back to what we did anyway (Tuple[Any])
Expand Down

0 comments on commit d314b67

Please sign in to comment.