Enums are Singletons - but not always?
Ethan Furman
ethan at stoneleaf.us
Sat May 23 16:15:51 EDT 2020
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.
--
~Ethan~
More information about the Python-list
mailing list