New submission from Alexander Marshalov <_...@marshalov.org>:
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". ---------- messages: 321891 nosy: amper priority: normal severity: normal status: open title: Behavior of the min/max with key=None type: enhancement versions: Python 3.8 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue34149> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com