[Python-ideas] Should nested classes in an Enum be Enum members?
Guido van Rossum
guido at python.org
Wed Jun 27 14:52:50 EDT 2018
Sounds to me really strange that the nested class would become a member.
Probably because everything becomes a member unless it's a function (maybe
On Wed, Jun 27, 2018 at 7:47 AM Ethan Furman <ethan at stoneleaf.us> wrote:
> Consider the following Enum definition:
> class Color(Enum):
> RED = 1
> GREEN = 2
> BLUE = 3
> def lower(self):
> return self.name.lower()
> def spam(self):
> return "I like %s eggs and spam!" % self.lower
> class SomeClass:
> Which of the above Color attributes are enums, and which aren't?
> - RED, GREEN, and BLUE are members
> - lower and spam() are not
> - SomeClass /is/ a member (but not its instances)
> Should `SomeClass` be an enum member? When would it be useful to have
> an embedded class in an Enum be an enum member?
> The only example I have seen so far of nested classes in an Enum is when
> folks want to make an Enum of Enums, and the
> nested Enum should not itself be an enum member. Since the
> counter-example already works I haven't seen any requests
> for it. ;)
> So I'm asking the community: What real-world examples can you offer for
> either behavior? Cases where nested classes
> should be enum members, and cases where nested classes should not be
> Python-ideas mailing list
> Python-ideas at python.org
> Code of Conduct: http://python.org/psf/codeofconduct/
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas