STINNER Victor added the comment:

> This change has visible side effect: __members__ is no longer ordered.

This property of part of the PEP 435 (enum):
"The special attribute __members__ is an ordered dictionary mapping names to 
members."

IMHO if we really want to change this, it must be discussed on the python-dev 
mailing list.

To keep __members__ ordered, we can delay the creation of the OrderedDict at 
the first access to __members__: start with a dict, and use the ordered 
_all_member_names_ to created the ordered dictionary.

Attached patch implements this idea.

I checked enum.Enum and enum.IntEnum classes and the @enum.unique decorated: 
__members__ is not used to declare the class. Hum, I had to modify a little bit 
@enum.unique to not access __members__.

----------
nosy: +haypo
Added file: http://bugs.python.org/file40490/delayed_ordered_dict.patch

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

Reply via email to