Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -5616,7 +5616,11 @@ def visit_slice_expr(self, e: SliceExpr) -> Type:
if index:
t = self.accept(index)
self.chk.check_subtype(t, expected, index, message_registry.INVALID_SLICE_INDEX)
return self.named_type("builtins.slice")
type_args = [
NoneType() if arg is None else self.accept(arg)
for arg in [e.begin_index, e.end_index, e.stride]
]
return self.chk.named_generic_type("builtins.slice", type_args)

def visit_list_comprehension(self, e: ListComprehension) -> Type:
return self.check_generator_or_comprehension(
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/check-expressions.test
Original file line number Diff line number Diff line change
Expand Up @@ -1178,8 +1178,8 @@ class B: pass
[case testSlicingWithInvalidBase]

a: A
a[1:2] # E: Invalid index type "slice" for "A"; expected type "int"
a[:] # E: Invalid index type "slice" for "A"; expected type "int"
a[1:2] # E: Invalid index type "slice[int, int, None]" for "A"; expected type "int"
a[:] # E: Invalid index type "slice[None, None, None]" for "A"; expected type "int"
class A:
def __getitem__(self, n: int) -> 'A': pass
[builtins fixtures/slice.pyi]
Expand Down
Loading