Verifiably better, validated Enum for Python

Chris Angelico rosuav at gmail.com
Wed May 24 08:07:45 EDT 2017


On Wed, May 24, 2017 at 7:10 PM, Steve D'Aprano
<steve+python at pearwood.info> wrote:
> Although I wonder:
>
> - maybe the enumeration (the class ContentTypes) could have a nicer repr
> than
>
> <enum 'ContentTypes'>
>
> - maybe you could add functionality to freeze the enumeration so that new
> members cannot be added?
>
>
> class ContentTypes(Enum, frozen=True)
> class ContentTypes(FrozenEnum)

I'm sure it could be done. But would it really benefit anyone
anything? Java has "final" classes, which can't be subclassed; and I
haven't heard many people saying "I wish you would declare more of
your classes final" or "I wish Python let you declare a class as
final".

ChrisA



More information about the Python-list mailing list