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.

classification
Title: bisect: Allow a custom compare function
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.9
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: gpery, rhettinger, xtreak
Priority: normal Keywords: patch

Created on 2019-06-11 10:36 by gpery, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 13970 closed gpery, 2019-06-11 10:48
Messages (5)
msg345216 - (view) Author: G (gpery) * Date: 2019-06-11 10:36
All of bisect's functions (insort_{left,right}, bisect_{left,right}) can only use comparison of objects via __lt__.
They should support providing a custom comparison function.
msg345217 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-06-11 10:43
See also issue1451588. issue4356 for more discussion that also proposes to add key parameter.
msg345240 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2019-06-11 15:35
Sorry, but we've intentionally removed generic compare functions in favor of objects supporting __lt__.  That is now the one-way-to-do-it.  If needed for convenience, you can use functools.cmp_to_key to automatically build a wrapper.
msg345242 - (view) Author: G (gpery) * Date: 2019-06-11 15:40
What do you propose to do for objects outside your project?
Replace their __lt__ method with a context manager which replaces the original implementation, for lists at a time?

__lt__ is not good enough as a one-way-to-do-it solution.
issue4356 is also a good-enough solution for me, but __lt__ definitely isn't.
msg345308 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2019-06-12 05:33
> issue4356 is also a good-enough solution for me,

Then please leave this closed and let that issue run its course. 

Also, please don't take an argumentative tone or abuse setting the tracker status.
History
Date User Action Args
2022-04-11 14:59:16adminsetgithub: 81410
2019-06-12 05:33:05rhettingersetstatus: open -> closed

messages: + msg345308
2019-06-11 15:40:31gperysetstatus: closed -> open
resolution: rejected ->
messages: + msg345242
2019-06-11 15:35:03rhettingersetstatus: open -> closed
resolution: rejected
messages: + msg345240

stage: patch review -> resolved
2019-06-11 15:21:12rhettingersetassignee: rhettinger
versions: + Python 3.9
2019-06-11 10:48:29gperysetkeywords: + patch
stage: patch review
pull_requests: + pull_request13837
2019-06-11 10:43:04xtreaksetnosy: + xtreak
messages: + msg345217
2019-06-11 10:41:14xtreaksetnosy: + rhettinger
2019-06-11 10:36:53gperycreate