Skip to content

Commit b313f71

Browse files
committed
reorder if
1 parent eb5c51b commit b313f71

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

mypy/checker.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4858,25 +4858,22 @@ def get_types_from_except_handler(self, typ: Type, n: Expression) -> list[Type]:
48584858
"""Helper for check_except_handler_test to retrieve handler types."""
48594859
typ = get_proper_type(typ)
48604860
if isinstance(typ, TupleType):
4861-
# avoid recursion here, since we can accidentally unpack tuples inside
48624861
merged_type = make_simplified_union(typ.items)
48634862
if isinstance(merged_type, UnionType):
48644863
return merged_type.relevant_items()
48654864
return [merged_type]
4866-
elif isinstance(typ, UnionType):
4867-
# recursion is fine here for top-level Union
4868-
return [
4869-
union_typ
4870-
for item in typ.relevant_items()
4871-
for union_typ in self.get_types_from_except_handler(item, n)
4872-
]
48734865
elif is_named_instance(typ, "builtins.tuple"):
48744866
# variadic tuple
4875-
# avoid recursion here too
48764867
merged_type = make_simplified_union((typ.args[0],))
48774868
if isinstance(merged_type, UnionType):
48784869
return merged_type.relevant_items()
48794870
return [merged_type]
4871+
elif isinstance(typ, UnionType):
4872+
return [
4873+
union_typ
4874+
for item in typ.relevant_items()
4875+
for union_typ in self.get_types_from_except_handler(item, n)
4876+
]
48804877
else:
48814878
return [typ]
48824879

0 commit comments

Comments
 (0)