On Mon, 3 Apr 2023 at 15:54, Benedict Verhegghe <[email protected]> wrote:
>
> Enum is not a type, like the OP suggested:
>

Well, it is:

>>> isinstance(Enum, type)
True

but it has a metaclass, meaning that the type of Enum is a subclass of type.

>>> type(Enum)
<class 'enum.EnumType'>
>>> type(Enum).__bases__
(<class 'type'>,)

I mean, we wouldn't be subclassing it if it weren't a type.

The __len__ method is implemented on the metaclass to allow all Enum
subclasses to have lengths (ditto __iter__ to make them iterable), and
as a consequence of that, Enum itself has all the attributes that it
wants to give to its subclasses.

ChrisA
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/V2HVHKTK3HG6CV3NBZFISPV6H5PHTTYL/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to