Ethan Furman added the comment:

So what do we want Enum's __dir__ to report?

Normally we see things like __eq__, __dict__, __getnewargs__, etc.

For IntEnum there would be __abs__, __floor__, __div__, etc.

Do we want to worry about those kinds of differences?  I think we do.

And if we do, then we are looking at removing items to make our custom __dir__, 
and with each release we would have to revisit the blacklist of items we don't 
want (the tests would catch that for us, but it would still be effort to update 
the code).

What if we took what object.__dir__ gave us, then added the Enum members while 
removing the private, er, non-public data structures?

In other words, this dir in EnumMeta:

    def __dir__(cls):
        items = set(super().__dir__())
        disgard = set([m for m in items if _is_sunder(m)])
        members = set(cls.__members__)
        return sorted((items | members) ^ disgard)

with this Enum:

>>> class Color(enum.Enum):
...  RED = 1
...  BLUE = 2
...  GREEN = 3
... 

gives us this result:

>>> dir(Color)
['BLUE', 'GREEN', 'RED', '__class__', '__delattr__', '__dict__', '__dir__', 
'__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', 
'__getnewargs__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', 
'__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', 
'__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 
'name', 'value']

----------

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

Reply via email to