Skip to content

Don't sort dicts for display in Python >= 3.6#10958

Merged
Carreau merged 2 commits into
ipython:masterfrom
takluyver:py37-dont-sort-dict
Dec 30, 2017
Merged

Don't sort dicts for display in Python >= 3.6#10958
Carreau merged 2 commits into
ipython:masterfrom
takluyver:py37-dont-sort-dict

Conversation

@takluyver

Copy link
Copy Markdown
Member

Closes gh-10110

@takluyver takluyver added this to the 5.6 milestone Dec 21, 2017
Comment thread IPython/lib/pretty.py Outdated


MAX_SEQ_LENGTH = 1000
DICT_IS_ORDERED = sys.version_info >= (3, 7)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))
)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I lobby for not sorting on 3.6+ on the practicality over purity platform.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I've set it to 3.6.

@takluyver takluyver changed the title Don't sort dicts for display in Python >= 3.7 Don't sort dicts for display in Python >= 3.6 Dec 22, 2017
@Carreau Carreau merged commit fee7d92 into ipython:master Dec 30, 2017
Carreau added a commit that referenced this pull request Jan 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants