New submission from Eric Snow <ericsnowcurren...@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
messages: 358553
nosy: eric.snow
priority: normal
severity: normal
status: open
title: types.SimpleNamespace should preserve attribute ordering (?)
type: enhancement
versions: Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue39075>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to