[Python-ideas] Should nested classes in an Enum be Enum members?

Steven D'Aprano steve at pearwood.info
Thu Jun 28 20:25:08 EDT 2018


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()

for the (dubious?) advantage of having

    Colors.NestedClass

treated as a colour enum.


> But when a nested class is not a member, you 
> would lost the possibility of making it a member (and this may break 
> existing code).

I must admit I'm still perplexed why I might want NestedClass to be an 
enum member.


-- 
Steve


More information about the Python-ideas mailing list