Zac-HD / shed

`shed` canonicalises Python code. Shed your legacy, stop bikeshedding, and move on. Black++

Home Page:https://pypi.org/project/shed/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect refactor when removing nested `sorted`

Zac-HD opened this issue · comments

>>> sorted(sorted([1, 12, 11]), key=lambda x: str(x)[0])
[1, 11, 12]
>>> sorted([1, 12, 11], key=lambda x: str(x)[0])
[1, 12, 11]

Replacing the latter with the former is clearly a mistake, because the stability of sorting is important! We should therefore avoid removing an inner sorted when either has a key= argument.

Fancier solutions involving returning a tuple from the key argument are out of scope, since covering all the scope-related edge cases really isn't worth the code it'd take.