Skip to content

Commit 510455a

Browse files
committed
Visit index expressions only once
1 parent cbb91e6 commit 510455a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

mypy/checkexpr.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5612,14 +5612,14 @@ def visit_slice_expr(self, e: SliceExpr) -> Type:
56125612
except KeyError:
56135613
supports_index = self.chk.named_type("builtins.int") # thanks, fixture life
56145614
expected = make_optional_type(supports_index)
5615+
type_args = []
56155616
for index in [e.begin_index, e.end_index, e.stride]:
56165617
if index:
56175618
t = self.accept(index)
56185619
self.chk.check_subtype(t, expected, index, message_registry.INVALID_SLICE_INDEX)
5619-
type_args = [
5620-
NoneType() if arg is None else self.accept(arg)
5621-
for arg in [e.begin_index, e.end_index, e.stride]
5622-
]
5620+
type_args.append(t)
5621+
else:
5622+
type_args.append(NoneType())
56235623
return self.chk.named_generic_type("builtins.slice", type_args)
56245624

56255625
def visit_list_comprehension(self, e: ListComprehension) -> Type:

0 commit comments

Comments
 (0)