[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
decorated)?
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
> @property
> def lower(self):
> return self.name.lower()
> def spam(self):
> return "I like %s eggs and spam!" % self.lower
> class SomeClass:
> pass
>
> Which of the above Color attributes are enums, and which aren't?
>
>
> .
>
>
> .
>
>
> .
>
> Answer:
>
> - RED, GREEN, and BLUE are members
>
> - lower and spam() are not
>
> - SomeClass /is/ a member (but not its instances)
>
>
> Question:
>
> 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
> members.
>
> Thanks!
>
> --
> ~Ethan~
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
--
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180627/bad19e02/attachment.html>
More information about the Python-ideas
mailing list