[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Enums are Singletons - but not always?

On 05/23/2020 11:57 AM, Richard Damon wrote:

> I don't think Python anywhere defines that a enum will be a singleton,
> and you should be checking for equality (==) not identity (is)

If you're not sure, please do a little research first.  We have enough bad information on the 'nets already.

According to Kushal's link:

> The most interesting thing about Enum members is that they are singletons.

The only time using `==` is necessary is for mixed-Enums, such as IntEnum, and you need to compare what could be an IntEnum member in code that could be using actual `int`s.