-
-
Notifications
You must be signed in to change notification settings - Fork 32k
Sorting tuples containing None
raises TypeError
in 3.11
#95173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Confirmed. Adding the release-blocker tag since this regression could affect reasonable real-world code. cc @pablogsal as release manager and @rhettinger and @tim-one who where involved with #29076 |
I suggest reverting the PR. It was a minor optimization that was tenuous because it was premised on sorting not having made explicit promises about what it would do with objects that didn't define a total ordering. In retrospect, that was a mistake because that premise was extended to tuples where we do have explicit promises about when We've documented that sorting only calls Additionally, this PR made
Possibly, the PR could restored someday if fallback logic were to restore consistent sequence comparison guarantees. Also, it might be worth discussing whether |
I am producing to revert #29076 to unblock the 3.11b5 release of next week |
I agree that it's safest to just revert for now, to unblock 3.11. But I don't think the optimization is necessarily doomed: we could decide to only apply it to situations where it's actually known to be safe, something like this: diff --git a/Objects/listobject.c b/Objects/listobject.c
index 83dfb7da01..38a99849b7 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -2455,16 +2455,10 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse)
ms.key_compare = safe_object_compare;
}
- if (keys_are_in_tuples) {
- /* Make sure we're not dealing with tuples of tuples
- * (remember: here, key_type refers list [key[0] for key in keys]) */
- if (key_type == &PyTuple_Type) {
- ms.tuple_elem_compare = safe_object_compare;
- }
- else {
- ms.tuple_elem_compare = ms.key_compare;
- }
-
+ if (keys_are_in_tuples && ms.key_compare != unsafe_object_compare
+ && ms.key_compare != safe_object_compare) {
+ /* For use when each key[0] has the same safe type */
+ ms.tuple_elem_compare = ms.key_compare;
ms.key_compare = unsafe_tuple_compare;
ms.first_tuple_items_resolved_it = 1; /* be optimistic */
} If the |
(cherry picked from commit 9007dec) Co-authored-by: Pablo Galindo Salgado <[email protected]>
(cherry picked from commit 9007dec) Co-authored-by: Pablo Galindo Salgado <[email protected]>
…one (pythonGH-95464) (cherry picked from commit c0cd790) Co-authored-by: Jacob Walls <[email protected]>
…H-95464) (cherry picked from commit c0cd790) Co-authored-by: Jacob Walls <[email protected]>
Uh oh!
There was an error while loading. Please reload this page.
Bug report
3.10
3.11.0b4
Sorting lists works fine:
From the release notes, I expect this is due to #29076, however the release notes merely say that the "order of the result may differ", not that comparisons might newly raise
TypeError
:And the issue discussion says this about
sorted()
:So while I agree with the sentiment that it's not great to be sorting tuples containing elements without a total ordering, I wonder if the current release note might merit some editing.
Real-life example involved a pattern like:
The text was updated successfully, but these errors were encountered: