From d314b67a3d1c07a871cf510de86a357c8965661c Mon Sep 17 00:00:00 2001 From: Jordandev678 <20153053+Jordandev678@users.noreply.github.com> Date: Wed, 18 Sep 2024 20:49:59 +0000 Subject: [PATCH] Update node checks to be more type specific and rename typ to argtyp --- mypy/checkexpr.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py index 7d5af0fba6cc..21ed7e420ff4 100644 --- a/mypy/checkexpr.py +++ b/mypy/checkexpr.py @@ -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])