This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ethan.furman
Recipients barry, eli.bendersky, ethan.furman, ned.deily, python-dev
Date 2013-08-12.00:05:22
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1376265923.48.0.766350477264.issue18693@psf.upfronthosting.co.za>
In-reply-to
Content
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']
History
Date User Action Args
2013-08-12 00:05:23ethan.furmansetrecipients: + ethan.furman, barry, ned.deily, eli.bendersky, python-dev
2013-08-12 00:05:23ethan.furmansetmessageid: <1376265923.48.0.766350477264.issue18693@psf.upfronthosting.co.za>
2013-08-12 00:05:23ethan.furmanlinkissue18693 messages
2013-08-12 00:05:22ethan.furmancreate