bpo-34149: Behavior of the min/max with key=None#8328
bpo-34149: Behavior of the min/max with key=None#8328rhettinger merged 3 commits intopython:masterfrom Amper:master
Conversation
|
Amper, please add a NEWS entry using blurb.py (see the devguide for details). If Serhiy don't feel strongly enough about this to reject this PR, I'll accept and apply it shortly. I'm persuaded by your idea that min(), max(), nsmallest(), nlargest(), sorted(), and itertools.groupby() should ideally have the same API for key functions. Syncing of those APIs would be a minor improvement. As Serhiy pointed out, this does complicate the type signature a bit, but that is of small concern given that the other four functions listed have already gone down this path. |
|
This also needs a documentation update including a versionchanged directive. |
|
@rhettinger, ok, i have no experience in this, but I'll try to do it tomorrow |
|
@rhettinger Is everything done right? |
https://bugs.python.org/issue34149
I was faced with the fact that the behavior of the functions "min"/"max" and "sorted" is a little different.
For example, this code works fine:
But the same example for "min" and "max" doesn't work:
That is why the heapq library has this code:
At the same time, there are many places where such checks are not performed for the "sorted" function. I think the behavior of the "min" / "max" / "sorted" functions should be unified. That is, they should work as if "None" is the default value for "key".
https://bugs.python.org/issue34149