
April 3, 2023
1:53 a.m.
On Mon, 3 Apr 2023 at 15:54, Benedict Verhegghe <bverheg@gmail.com> 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