-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
OrderedDict dict/list representation #101446
Labels
type-feature
A feature request or enhancement
Comments
I agree that the proposed new |
sobolevn
added a commit
to sobolevn/cpython
that referenced
this issue
Feb 7, 2023
rhettinger
pushed a commit
that referenced
this issue
Feb 8, 2023
rwgk
pushed a commit
to rwgk/pybind11
that referenced
this issue
Mar 9, 2023
…aks between Python 3.12alpha3 (still working) and 3.12alpha6 (broken): ``` str(OrderedDict([(1, "a"), (2, "b")])) ``` Old: ``` OrderedDict([(1, 'a'), (2, 'b')]) ``` New: ``` OrderedDict({1: 'a', 2: 'b'}) ``` See also: python/cpython#101446
rwgk
pushed a commit
to pybind/pybind11
that referenced
this issue
Mar 9, 2023
…aks between Python 3.12alpha3 (still working) and 3.12alpha6 (broken): (#4559) ``` str(OrderedDict([(1, "a"), (2, "b")])) ``` Old: ``` OrderedDict([(1, 'a'), (2, 'b')]) ``` New: ``` OrderedDict({1: 'a', 2: 'b'}) ``` See also: python/cpython#101446
Currently this change is mentioned only in the 3.12 Changelog but not under the top-level What’s New In Python 3.12 page. @Yhg1s suggested that it should be mentioned in What’s New, too. Should I file a separate bug for this, or is this comment sufficient as a reminder? |
7 tasks
12 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I know that for historical purposes,
OrderedDict.__repr__
displays key-value pairs in the format of[(key, value), ...]
, since the{key: value, ...}
representation did not respect the ordering thatOrderedDict
needs. However, this was only in the past and it has become a while since dictionaries have become ordered, so I was wondering if changing theOrderedDict.__repr__
to displayOrderedDict({key: value, ...})
instead would be fine. The main rationale is that this is syntactically cleaner to read, often I have found the other representation to be a lot more clunky. Other than potentially breaking things like doc-tests, I don't see much issue with this. The only potential ambiguity that I see is the fact that one might not be immediately sure that the dictionary is ordered, but the fact that it is wrapped byOrderedDict(...)
would probably dispel any doubts.Linked PRs
repr
ofcollections.OrderedDict
#101661The text was updated successfully, but these errors were encountered: