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.

Author amper
Recipients amper
Date 2018-07-18.16:06:09
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1531929969.94.0.56676864532.issue34149@psf.upfronthosting.co.za>
In-reply-to
Content
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".
History
Date User Action Args
2018-07-18 16:06:09ampersetrecipients: + amper
2018-07-18 16:06:09ampersetmessageid: <1531929969.94.0.56676864532.issue34149@psf.upfronthosting.co.za>
2018-07-18 16:06:09amperlinkissue34149 messages
2018-07-18 16:06:09ampercreate