You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ktbarrettmannequin opened this issue
Apr 14, 2021
· 4 comments
Labels
3.7 (EOL)end of life3.8only security fixes3.9only security fixes3.10only security fixesstdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error
The range builtin type is a collections.abc.Sequence, which in Python 3.5 added the optional start and stop arguments to the index method of Sequences. However, range.index does not support these optional arguments required by Sequence.
I noticed this when creating a wrapper type around range which was a Sequence. mypy complained 'Signature of "index" incompatible with supertype "Sequence"', but attempting to pass the values raised 'TypeError: index() takes exactly one argument (3 given)'.
Additionally, this causes issues with mypy. If you subclass Sequence, mypy will complain if you don't have the optional start and stop arguments in the index method. I would need to feed them into a range object in my implementation. I guess in my case I'm expected to just reject them? This breaks substitutability in my class.
It also breaks substitutability with list, tuples, every built-in Sequence type as well.
3.7 (EOL)end of life3.8only security fixes3.9only security fixes3.10only security fixesstdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: