Message321891
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:
>>> sorted([3, 2, 1], key=None)
[1, 2, 3]
But the same example for "min" and "max" doesn't work:
>>> min([3, 2, 1], key=None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not callable
That is why the heapq library has this code:
...
def nsmallest(n, iterable, key=None):
...
if key is None:
result = min(it, default=sentinel)
else:
result = min(it, default=sentinel, key=key)
...
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". |
|
Date |
User |
Action |
Args |
2018-07-18 16:06:09 | amper | set | recipients:
+ amper |
2018-07-18 16:06:09 | amper | set | messageid: <1531929969.94.0.56676864532.issue34149@psf.upfronthosting.co.za> |
2018-07-18 16:06:09 | amper | link | issue34149 messages |
2018-07-18 16:06:09 | amper | create | |
|