Issue39075
Created on 2019-12-17 16:21 by eric.snow, last changed 2020-05-16 01:30 by eric.snow. This issue is now closed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 19430 | merged | ZackerySpytz, 2020-04-08 05:45 | |
| Messages (9) | |||
|---|---|---|---|
| msg358553 - (view) | Author: Eric Snow (eric.snow) * | Date: 2019-12-17 16:21 | |
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. |
|||
| msg358563 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * | Date: 2019-12-17 18:10 | |
We usually do not iterate all attributes, and dir() always sort attribute names. |
|||
| msg358613 - (view) | Author: Raymond Hettinger (rhettinger) * | Date: 2019-12-18 06:07 | |
+1 for dropping the sort. Also, the repr should be made to round-trip with eval(). |
|||
| msg358785 - (view) | Author: hai shi (shihai1991) * | Date: 2019-12-22 05:08 | |
IMHO, dropping the sort should be a default behavior. If some user need this feature, maybe we could supply a param to open the sort function or not? |
|||
| msg358786 - (view) | Author: Raymond Hettinger (rhettinger) * | Date: 2019-12-22 08:13 | |
@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 :-) |
|||
| msg358793 - (view) | Author: hai shi (shihai1991) * | Date: 2019-12-22 16:04 | |
@Raymond OK, copy that. |
|||
| msg358913 - (view) | Author: Eric Snow (eric.snow) * | Date: 2019-12-27 20:15 | |
> IMHO, dropping the sort should be a default behavior. If some user need > this feature, maybe we could supply a param to open the sort function or not? Consider opening a separate issue (or start a thread on python-ideas) about adding a more sophisticated implementation to the stdlib's "reprlib" module. If you do so then please draw from the argparse._AttributeHolder implementation. |
|||
| msg359119 - (view) | Author: hai shi (shihai1991) * | Date: 2019-12-31 15:28 | |
>Consider opening a separate issue (or start a thread on python-ideas) >about adding a more sophisticated implementation to the stdlib's >"reprlib" module. If you do so then please draw from the >argparse._AttributeHolder implementation. FWIW, i created a new bpo: https://bugs.python.org/issue39173 |
|||
| msg368995 - (view) | Author: miss-islington (miss-islington) | Date: 2020-05-16 01:28 | |
New changeset 6b6092f533f0e4787b8564c4fad6ec6d1018af0d by Zackery Spytz in branch 'master': bpo-39075: types.SimpleNamespace no longer sorts attributes in its repr (GH-19430) https://github.com/python/cpython/commit/6b6092f533f0e4787b8564c4fad6ec6d1018af0d |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2020-05-16 01:30:01 | eric.snow | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2020-05-16 01:28:01 | miss-islington | set | nosy:
+ miss-islington messages: + msg368995 |
| 2020-04-08 05:45:46 | ZackerySpytz | set | keywords:
+ patch nosy: + ZackerySpytz pull_requests:
+ pull_request18787 |
| 2019-12-31 15:28:00 | shihai1991 | set | messages: + msg359119 |
| 2019-12-27 20:15:15 | eric.snow | set | messages: + msg358913 |
| 2019-12-22 16:04:56 | shihai1991 | set | messages: + msg358793 |
| 2019-12-22 08:13:37 | rhettinger | set | messages: + msg358786 |
| 2019-12-22 05:08:03 | shihai1991 | set | nosy:
+ shihai1991 messages: + msg358785 |
| 2019-12-18 06:07:21 | rhettinger | set | messages: + msg358613 |
| 2019-12-17 18:10:16 | serhiy.storchaka | set | nosy:
+ rhettinger, yselivanov, serhiy.storchaka messages: + msg358563 |
| 2019-12-17 16:46:26 | xtreak | set | nosy:
+ xtreak |
| 2019-12-17 16:30:05 | eric.snow | set | stage: needs patch |
| 2019-12-17 16:21:21 | eric.snow | create | |