Skip to content

Commit

Permalink
Save a function call by storing length of union items
Browse files Browse the repository at this point in the history
Co-authored-by: Hashem <[email protected]>
  • Loading branch information
bergkvist and Hnasar authored Aug 8, 2024
1 parent c62587a commit e418d98
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions mypy/checkpattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,10 @@ def visit_sequence_pattern(self, o: SequencePattern) -> PatternType:
if not isinstance(get_proper_type(typ), UninhabitedType):
union_items.append(typ)
union_captures.update(capture)
if len(union_items) == 0:
num_items = len(union_items)
if num_items == 0:
typ = UninhabitedType()
elif len(union_items) == 1:
elif num_items == 1:
typ = union_items[0]
else:
typ = UnionType(items=union_items)
Expand Down

0 comments on commit e418d98

Please sign in to comment.