This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author gwk
Recipients gwk, rhettinger, serhiy.storchaka
Date 2017-03-29.17:57:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1490810229.09.0.656915149232.issue29935@psf.upfronthosting.co.za>
In-reply-to
Content
I think it is a mistake not to support None values. Please consider:

The existing message clearly suggests that the intent is to support the same set of values as the start/stop parameters of the slice type. str, bytes, and bytearray all support None for `index`, as well as `count`, `find`, `rfind`, and `rindex`.

Not supporting None makes the type signature of list.index and tuple.index subtly different from those of str, bytes, and bytearray, when they could otherwise be interchangeable. It makes the type signature of index inconsistent across the types.

Furthermore, it makes converting slice start/stop to these arguments a pain. Compare the following:

    seq.index(start=slice.start, end=slice.stop) # accepting None

    seq.index(start=(0 if slice.start is None else slice.start), end=(len(seq) if slice.stop is None else slice.stop)) # current behavior.

I do not buy the argument that the latter communicates intent better, and it is adds bug-prone baggage to every call site.


Similarly, being able to pass None for end/stop parameters is very convenient in the case of optional passthrough arguments, saving the programmer from this:
def f(seq, end=None):
  i = seq.index(start=0, end=(len(seq) if end is None else end)) # current behavior.
  ...

Note that for the programmer writing `f`, None (or some other distinct sentinel value) is a *requirement* for correctness, because end=len(seq) is incorrect.

I would understand opposition to this on the basis of not changing existing behavior in any way, but "communicating intent" seems like a thin argument in comparison to the above.
History
Date User Action Args
2017-03-29 17:57:09gwksetrecipients: + gwk, rhettinger, serhiy.storchaka
2017-03-29 17:57:09gwksetmessageid: <1490810229.09.0.656915149232.issue29935@psf.upfronthosting.co.za>
2017-03-29 17:57:09gwklinkissue29935 messages
2017-03-29 17:57:08gwkcreate