Don't sort dicts for display in Python >= 3.6 #10958
Conversation
@@ -95,6 +95,7 @@ def _repr_pretty_(self, p, cycle): | |||
|
|||
|
|||
MAX_SEQ_LENGTH = 1000 | |||
DICT_IS_ORDERED = sys.version_info >= (3, 7) |
njsmith
Dec 21, 2017
Contributor
Maybe:
DICT_IS_ORDERED = (
sys.version_info >= (3, 7)
or platform.python_implementation() == "PyPy"
or (platform.python_implementation() == "CPython" and sys.version_info >= (3, 6))
)
Maybe:
DICT_IS_ORDERED = (
sys.version_info >= (3, 7)
or platform.python_implementation() == "PyPy"
or (platform.python_implementation() == "CPython" and sys.version_info >= (3, 6))
)
takluyver
Dec 21, 2017
Author
Member
I'm inclined to use 3.7, because that's when Python dicts are defined as being ordered, rather than it being up to the implementation.
If we want to push it faster, I'd rather say 3.6 than start checking which implementation it is. But following the language definition feels like the better thing to do.
I'm inclined to use 3.7, because that's when Python dicts are defined as being ordered, rather than it being up to the implementation.
If we want to push it faster, I'd rather say 3.6 than start checking which implementation it is. But following the language definition feels like the better thing to do.
njsmith
Dec 21, 2017
Contributor
I was going to suggest making it sys.version_info >= (3, 6)
, and then guessed that you would give the pedantically correct response that technically there could someday be a 3.6 valid implementation that doesn't have ordered dicts, so I switched to the exact pedantically accurate check you see above :-).
I'm not sure how it helps end-users to order their dicts differently on 3.6 versus 3.7, given that in practice the actual interpreter behavior is identical. Most users don't understand the complex metaphysical question of how the exact same behavior is different depending on whether it's nominally accidental or nominally intentional. OTOH we do have multiple reports from people that the sorting on 3.6 is causing them pain right now.
I was going to suggest making it sys.version_info >= (3, 6)
, and then guessed that you would give the pedantically correct response that technically there could someday be a 3.6 valid implementation that doesn't have ordered dicts, so I switched to the exact pedantically accurate check you see above :-).
I'm not sure how it helps end-users to order their dicts differently on 3.6 versus 3.7, given that in practice the actual interpreter behavior is identical. Most users don't understand the complex metaphysical question of how the exact same behavior is different depending on whether it's nominally accidental or nominally intentional. OTOH we do have multiple reports from people that the sorting on 3.6 is causing them pain right now.
tacaswell
Dec 21, 2017
Contributor
I lobby for not sorting on 3.6+ on the practicality over purity platform.
I lobby for not sorting on 3.6+ on the practicality over purity platform.
takluyver
Dec 21, 2017
Author
Member
OK, I've set it to 3.6.
OK, I've set it to 3.6.
fee7d92
into
ipython:master
Backport PR #10958 on branch 5.x
Closes gh-10110