[New-bugs-announce] [issue39075] types.SimpleNamespace should preserve attribute ordering (?)
report at bugs.python.org
Tue Dec 17 11:21:21 EST 2019
New submission from Eric Snow <ericsnowcurrently at gmail.com>:
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.
components: Interpreter Core
title: types.SimpleNamespace should preserve attribute ordering (?)
versions: Python 3.9
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce