![](https://secure.gravatar.com/avatar/d67ab5d94c2fed8ab6b727b62dc1b213.jpg?s=120&d=mm&r=g)
On Mon, 3 Apr 2023 at 17:57, Benedict Verhegghe <bverheg@gmail.com> wrote:
Well, it's not an object of type 'type' like the list or dict mentioned by the OP, for which len() give a TypeError: object of type 'type' has no len()
I'm not sure what you mean here. Enum is of type EnumMeta, which is a subclass of type. That means that, according to the normal rules of type hierarchy, Enum is indeed a type. Types add functionality that the parent type (with some Exceptions), so it should be no surprise that EnumMeta can add a __len__ method that type itself didn't have.
Any derived class of Enum will also return True for isinstance(..., type).
Yes, that is correct. Any subclass of Enum will also be a type, and will have a length.
class TestEnum(Enum): ... SPAM = 1 ... HAM = 2 ... isinstance(TestEnum, type) True len(TestEnum) 2
Should the derived classes then neither have a meaningful result for len()? Enum and derived classes hold a container with a fixed set of values. It makes perfectly sense to ask for the number of possible values, even when there are none.
Yeah, and I'm of the opinion that it's not a problem for Enum to have zero possible values, but to have the concept of values. Although it also wouldn't be a problem if it didn't. ChrisA