Skip to content

Slice index false positive #3442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pkch opened this issue May 24, 2017 · 4 comments
Closed

Slice index false positive #3442

pkch opened this issue May 24, 2017 · 4 comments

Comments

@pkch
Copy link
Contributor

pkch commented May 24, 2017

from typing import Union, Any

d: Union[int, None]
q: Any
q[0:d]  # error: Slice index must be an integer or None

Reported by @chrish42.

@gvanrossum
Copy link
Member

Probably a typeshed issue.

@JelleZijlstra
Copy link
Member

I don't think so, this is mypy's general slicing check, not a specific __getitem__ override. Looks like the bug is in visit_slice_expr in checkexpr.py. The error message says that int or None is accepted, but the code only accepts int.

@chrish42
Copy link

chrish42 commented May 24, 2017

Furthermore, None as a slice index works in at least some cases:

>>> range(10)[3:None]
range(3, 10)

So, at least for some cases, the code in visit_slice_expr should be more lenient and accept None as a slice index.

@gvanrossum
Copy link
Member

OK, I thought mypy usually eventually defer to a dunder method, but if it doesn't in this case it's a mypy bug, perhaps related to strict optional.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants