Re:PEP 435 Accepted – Adding an Enum type to the Python stan...
by dietrichepp on Friday May 10, 2013 @03:56PM
(#5688333)
There is a technical reason why the class name is passed into the API, and it's the same for other functions which create types (collections.namedtuple(), and type(), for example). You want to be able to print out the class name when you print an enum, but there is no other reliable way to figure out the class name. In Python, a class is just another value, like functions and integers and its name is nothing special. When you define a class normally, the name and dictionary get passed to the type() function.
[ Parent
| on HN ]
Re:PEP 435 Accepted – Adding an Enum type to the Python stan...
by bsimpson on Friday May 10, 2013 @06:12PM
(#5688966)
I understand that, but I'm not sure it matter. Is it worth the ugliness in the API to print out the class name when you run print? Is 'api' that much worse than "ImportMethod.API"?
Re:PEP 435 Accepted – Adding an Enum type to the Python stan...
by dietrichepp on Saturday May 11, 2013 @01:44AM
(#5689808)
That's not all it's there for. Python programmers expect to be able to do things like print(obj.__class__.__name__). You're definitely free to write your own alternative Enum, however, since it's just a library function.