[New-bugs-announce] [issue34842] Incorrect error messages in bisect

Dan Snider report at bugs.python.org
Sat Sep 29 05:29:49 EDT 2018


New submission from Dan Snider <mr.assume.away at gmail.com>:

internal_bisect_left and internal_bisect_right use PySequence_Size when a "hi" argument wasn't provided, which causes this silly error message:

    >>> bisect.bisect_right(dict.fromkeys(range(10)), 5)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: object of type 'dict' has no len()

They could use PyObject_Size and let PySequence_GetItem in the loop catch the error:

    >>> bisect.bisect_right(dict.fromkeys(range(10)), 5, 0, 10)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: 'dict' object does not support indexing

Since that actually makes sense and is more efficient / less verbose than adding a PySequence_Check.

----------
components: Interpreter Core
messages: 326672
nosy: bup
priority: normal
severity: normal
status: open
title: Incorrect error messages in bisect
versions: Python 3.6, Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34842>
_______________________________________


More information about the New-bugs-announce mailing list