29.06.18 03:25, Steven D'Aprano пише:
On Thu, Jun 28, 2018 at 06:57:45AM +0300, Serhiy Storchaka wrote:
Making a nested class a member you
don't lost anything, because you always can make it not-nested if you
don't want it be a member.
You lose the ability to have
Colors.RED.NestedClass() # returns something useful
# similar to Colors.RED.method()
Since NestedClass is an enum member, you should use
Colors.RED.NestedClass.value() or just Colors.NestedClass.value() for
calling its value.
If you don't want it be a member, just don't initialize it in the enum body.
class Color(Enum):
RED = 1
class NestedClass:
pass
Color.RED.NestedClass = NestedClass
Now Color.RED.NestedClass() can return something useful.
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/