Author ethan.furman
Recipients barry, eli.bendersky, ethan.furman, ncoghlan, pitrou
Date 2013-09-16.00:00:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1379289654.59.0.452504541982.issue19030@psf.upfronthosting.co.za>
In-reply-to
Content
Due to the odd nature of Enum classes and instances, the normal methods used by inspect.getmembers and inspect.classify_class_attrs are insufficient.

By special casing Enum inside those two functions the correct information can be returned.

Here is an example of the problem:

=======================================================================================
--> class Test(enum.Enum):
...   this = 'that'
...   these = 'those'
...   whose = 'mine'
...   name = 'Python'
...   value = 'awesome'
...   def what(self):
...     return "%s is %s!" % (self.name, self.value)
... 

--> help(Test)
Help on Test in module __main__ object:

class Test(enum.Enum)
 |  Method resolution order:
 |      Test
 |      enum.Enum
 |      builtins.object
 |  
 |  Data and other attributes defined here:
 |  
 |  these = <Test.these: 'those'>
 |  
 |  this = <Test.this: 'that'>
 |  
 |  whose = <Test.whose: 'mine'>
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors inherited from enum.Enum:
 |  
 |  name
 |      The name of the Enum member.
 |  
 |  value
 |      The value of the Enum member.
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors inherited from enum.EnumMeta:
 |  
 |  __members__
 |      Returns a mapping of member name->value.
 |      
 |      This mapping lists all enum members, including aliases. Note that this
 |      is a read-only view of the internal mapping.
(END)
=======================================================================================

As can be seen, 'name' and 'value' are not showing up as enum members.
History
Date User Action Args
2013-09-16 00:00:54ethan.furmansetrecipients: + ethan.furman, barry, ncoghlan, pitrou, eli.bendersky
2013-09-16 00:00:54ethan.furmansetmessageid: <1379289654.59.0.452504541982.issue19030@psf.upfronthosting.co.za>
2013-09-16 00:00:54ethan.furmanlinkissue19030 messages
2013-09-16 00:00:54ethan.furmancreate