Skip to content

TypeError in bisect when called with key argument #117848

Closed
@c-m-m-kobayashi

Description

@c-m-m-kobayashi

Bug report

Bug description:

bisect functions raise TypeError when called with key argument.
Here is a minimum code to reproduce the issue:

import bisect
import operator

a = [('one', 1), ('two', 2)]
print(bisect.bisect(a, ('one', 1), key=operator.itemgetter(0)))

This results in the following error:

Traceback (most recent call last):
  File "/path/to/bisect_test.py", line 5, in <module>
    print(bisect.bisect(a, ('one', 1), key=operator.itemgetter(0)))
          ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '<' not supported between instances of 'tuple' and 'str'

It seems that picking an item in a tuple has a problem.

CPython versions tested on:

3.12

Operating systems tested on:

macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions