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 Sergey.Kirpichev
Recipients Sergey.Kirpichev
Date 2015-04-29.13:30:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1430314243.47.0.686981874079.issue24075@psf.upfronthosting.co.za>
In-reply-to
Content
If there is nothing to sort (i.e. one item), why call key function at all?

In my practical situation, simplest key() function will lead to recursion in case of such trivial lists.  I can make similar cmp-type function (i.e. mycmp=lambda a, b: cmp(key(a), key(b))) and then wrap this with cmp_to_key.  But that looks silly.

Simple test case:
$ cat a.py
a = [1]

def spam(x):
    raise Exception

a.sort(key=spam)
print(a)
$ python a.py 
Traceback (most recent call last):
  File "a.py", line 6, in <module>
    a.sort(key=spam)
  File "a.py", line 4, in spam
    raise Exception
Exception
History
Date User Action Args
2015-04-29 13:30:43Sergey.Kirpichevsetrecipients: + Sergey.Kirpichev
2015-04-29 13:30:43Sergey.Kirpichevsetmessageid: <1430314243.47.0.686981874079.issue24075@psf.upfronthosting.co.za>
2015-04-29 13:30:43Sergey.Kirpichevlinkissue24075 messages
2015-04-29 13:30:43Sergey.Kirpichevcreate