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 zach.ware
Recipients alex, barry, benjamin.peterson, docs@python, eli.bendersky, ethan.furman, ezio.melotti, gvanrossum, isoschiz, ncoghlan, pconnell, python-dev, zach.ware
Date 2013-05-13.20:17:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1368476246.75.0.836362831038.issue17947@psf.upfronthosting.co.za>
In-reply-to
Content
I've come across something in the implementation here that I'd like some clarification on.  What is the purpose of overriding __dir__ in Enum and EnumMeta?  It doesn't change any behavior that I'm aware of, just makes things look a little nicer when someone calls dir() on their Enum.  And, in fact, it can make things a little confusing.  For example:

>>> class Test(enum.Enum):
...     foo = 1
...     bar = 2
...     baz = 3
...
>>> dir(Test)
['__class__', '__doc__', '__members__', 'bar', 'baz', 'foo']
>>> Test.mro
<built-in method mro of EnumMeta object at 0x01D94D20>

This brings up another interesting case:

>>> class Test2(enum.Enum):
...     mro = 1
...     _create = 2
...
>>> dir(Test2)
['__class__', '__doc__', '__members__', '_create', 'mro']
>>> Test2.__members__
mappingproxy(OrderedDict([('mro', <Test2.mro: 1>), ('_create', <Test2._create: 2>)]))
>>> Test2['mro']
<Test2.mro: 1>
>>> Test2.mro
<built-in method mro of EnumMeta object at 0x01D90210>
>>> Test2._create
<bound method type._create of <class 'enum.EnumMeta'>>
>>>

From using "mro" or "_create", I would have expected either ValueError or for them to work properly.  I don't know whether this should be fixed (one way or the other), documented, or just left alone; those kind of names really shouldn't ever be used anyway.  It's something I stumbled across, though, and I just wanted to make sure that those who do have opinions that matter are aware of it :)
History
Date User Action Args
2013-05-13 20:17:26zach.waresetrecipients: + zach.ware, gvanrossum, barry, ncoghlan, benjamin.peterson, ezio.melotti, alex, eli.bendersky, docs@python, ethan.furman, python-dev, pconnell, isoschiz
2013-05-13 20:17:26zach.waresetmessageid: <1368476246.75.0.836362831038.issue17947@psf.upfronthosting.co.za>
2013-05-13 20:17:26zach.warelinkissue17947 messages
2013-05-13 20:17:26zach.warecreate