Enum is not a type, like the OP suggested:
from enum import Enum
class Color(Enum):
WHITE = 1
type(Color)
<class 'enum.EnumMeta'>
type(Enum)
<class 'enum.EnumMeta'>
type(enum.EnumMeta)
<class 'type'>
Enum.__len__
<bound method EnumMeta.__len__ of <enum 'Enum'>>
So to me it looks like Enum is just a generic, empty enum. The __len__
method is implemented in EnumMeta.
Op 3/04/2023 om 00:18 schreef Greg Ewing:
On 2/04/23 6:36 pm, Benedict Verhegghe wrote:
An Enum is functionally a container with a limited set of constants.
Why should it not be legitimate to ask for the number of constants in it?
But Enum itself isn't an enum, it's a constructor for enums.
I think len() just happens to work on it as a side effect
of the way enums are implemented.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/python-ideas@python.org/message/T7KLPDDRUWIFLLYNTWW6STDZHTTZXBEU/
Code of Conduct: http://python.org/psf/codeofconduct/