[Python-ideas] Re: len(Enum) should raise TypeError

2023-04-02 Thread Chris Angelico
On Mon, 3 Apr 2023 at 15:54, Benedict Verhegghe 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) >>> type(Enum).__bases__ (,) I mean, we wouldn't be

[Python-ideas] Re: len(Enum) should raise TypeError

2023-04-02 Thread Benedict Verhegghe
Enum is not a type, like the OP suggested: from enum import Enum class Color(Enum): WHITE = 1 type(Color) type(Enum) type(enum.EnumMeta) Enum.__len__ > 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 schre

[Python-ideas] Re: len(Enum) should raise TypeError

2023-04-02 Thread Chris Angelico
On Mon, 3 Apr 2023 at 08:28, Greg Ewing wrote: > > 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 construc

[Python-ideas] Re: len(Enum) should raise TypeError

2023-04-02 Thread 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