[issue29935] list and tuple index methods should accept None parameters

George King report at bugs.python.org
Tue Mar 28 12:16:22 EDT 2017


New submission from George King:

As of python3.6, passing None to the start/end parameters of `list.index` and `tuple.index` raises the following exception:
"slice indices must be integers or None or have an __index__ method"

This suggests that the intent is to support None as a valid input. This would be quite useful for the end parameter, where the sensible default is len(self) rather than a constant. Note also that str, bytes, and bytearray all support None.

I suggest that CPython be patched to support None for start/end. Otherwise, at the very least the exception message should be changed.

Accepting None will make the optional start/end parameters for this method more consistent across the types, which is especially helpful when using type annotations / checking.

----------
messages: 290737
nosy: gwk
priority: normal
severity: normal
status: open
title: list and tuple index methods should accept None parameters

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29935>
_______________________________________


More information about the Python-bugs-list mailing list