-
-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
types.SimpleNamespace should preserve attribute ordering (?) #83256
Comments
types.SimpleNamespace was added in 3.3 (for use in sys.implementation; see PEP-421), which predates the change to preserving insertion order in dict. At the time we chose to sort the attributes in the repr, both for ease of reading and for a consistent output. The question is, should SimpleNamespace stay as it is (sorted repr) or should it show the order in which attributes were added? On the one hand, alphabetical order can be useful since it makes it easier for readers to find attributes, especially when there are many. However, for other cases it is helpful for the repr to show the order in which attributes were added. FWIW, I favor changing the ordering in the repr to insertion-order. Either is relatively trivial to get after the fact (whether "sorted(vars(ns))" or "list(vars(ns))"), so I don't think any folks that benefit from alphabetical order will be seriously impacted. |
We usually do not iterate all attributes, and dir() always sort attribute names. |
+1 for dropping the sort. Also, the repr should be made to round-trip with eval(). |
IMHO, dropping the sort should be a default behavior. If some user need |
@haisai SimpleNamespace can't use keyword arguments because those are already used to pass in data. Also, we want to keep it simple; hence, the name :-) |
@Raymond OK, copy that. |
Consider opening a separate issue (or start a thread on python-ideas) |
FWIW, i created a new bpo: https://bugs.python.org/issue39173 |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: