bpo-33217: Raise TypeError for non-Enum lookups in Enums by RJ722 · Pull Request #6651 · python/cpython

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed that if we use cls.__qualname__ instead of type(Enum).__qualname__, we get a much better output.

For example if we have the following program

ABC = enum.Flag('ABC', 'a, b, c')
'test' in ABC

then after changing to cls.__qualname__, we get:

TypeError: Unsupported operands type(s) for 'in': 'str' and 'ABC'

which looks better than what we were getting before:

TypeError: Unsupported operands type(s) for 'in': 'str' and 'EnumMeta'

Which one should we use?