[Python-Dev] PEP520 and absence of definition_order (original) (raw)
Ethan Furman ethan at stoneleaf.us
Sun Sep 11 15:12:48 EDT 2016
- Previous message (by thread): [Python-Dev] PEP520 and absence of __definition_order__
- Next message (by thread): [Python-Dev] sys.path file feature
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 09/11/2016 01:55 AM, Victor Stinner wrote:
2016-09-10 3:49 GMT-04:00 Ethan Furman wrote:
With definitionorder Enum can display the actual creation order of enum members and methods, while relying on Enum.dict.keys() presents a jumbled mess with many attributes the user never wrote, the enum members either appearing /after/ all the methods (even if actually written before), or entirely absent. Python 3.5 also returns methods in Enum.dict(). So it would be a new feature, right?
definition_order is (would be) a new feature, yes.
The use case seems to be specific to Enum. Can't you add a new method which only returns members (ordered by insertion order)?
The use case is specific to any custom metaclass that does more than enhance the attributes and/or methods already in the class body.
list(myenum.membermaps.keys()) returns members, sorted by insertion order. Is it what you want?
That only includes members, not other attributes nor methods. What I want is to make sure the other points of PEP 520 are not forgotten about, and that Enum conforms to the accepted PEP.
Code: --- import enum
class Color(enum.Enum): red = 1 blue = red green = 2 print(Color.dict.keys()) print(list(Color.membermap.keys())) --- Python 3.5: --- dictkeys(['module', 'membernames', 'green', 'membertype', 'blue', 'value2membermap', 'membermap', 'new', 'red', 'doc']) ['red', 'blue', 'green'] --- Python 3.6: --- dictkeys(['generatenextvalue', 'module', 'doc', 'membernames', 'membermap', 'membertype', 'value2membermap', 'red', 'blue', 'green', 'new']) ['red', 'blue', 'green'] --- Note: It seems like dir(myenum) ignores "aliases" like blue=red in my example.
That is intentional.
--
Ethan
- Previous message (by thread): [Python-Dev] PEP520 and absence of __definition_order__
- Next message (by thread): [Python-Dev] sys.path file feature
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]