Skip to content
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

str method start/end parameters should accept values supporting __index__ #1110

Closed
gwk opened this issue Mar 28, 2017 · 3 comments
Closed

str method start/end parameters should accept values supporting __index__ #1110

gwk opened this issue Mar 28, 2017 · 3 comments
Labels
stubs: false positive Type checkers report false errors

Comments

@gwk
Copy link
Contributor

gwk commented Mar 28, 2017

str count, find, index, rfind, and rindex all accept int, None, or any value implementing __index__ for the start/end parameters. PR #1109 improves the annotation from int to Optional[Int], but still neglects the __index__ protocol. Rather than proposing a typing.SupportsIndex ABC, @JelleZijlstra suggested that we wait until PEP 544 to deal with this.

Note that there is a similar problem with list and tuple, with the additional caveat that CPython 3.6 does not accept None values but the raised exception suggests that they are supposed to. This deserves a bugs.python.org report.

@gwk
Copy link
Contributor Author

gwk commented Mar 28, 2017

Filed http://bugs.python.org/issue29935 for the list/tuple concern.

@srittau srittau added the stubs: false positive Type checkers report false errors label Oct 28, 2018
@srittau
Copy link
Collaborator

srittau commented Sep 17, 2020

Python 3.8 actually added SupportsIndex (which was backported to typing_extensions), so this should be possible now.

@asottile
Copy link
Contributor

also noticing this for bytes.__getitem__ (and presumably __getitem__ for a lot of the builtin types as well)

hatal175 added a commit to hatal175/typeshed that referenced this issue Apr 17, 2021
@Akuli Akuli closed this as completed in f44f38f Apr 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stubs: false positive Type checkers report false errors
Projects
None yet
Development

No branches or pull requests

4 participants