Python Enum Gotcha

There is plenty of useful information in Why You Should Use More Enums In Python – A gentle introduction to enumerations in Python. After reading it I decided to look into using Enums more. Unfortunately I hit a major Gotcha quite quickly.

Basically, comparisons don’t work with vanilla Enum (unlike IntEnum). Checking the official Python documentation seemed to confirm this understanding:

“Comparisons against non-enumeration values will always compare not equal (again, IntEnum was explicitly designed to behave differently …)” —

In the snippet below, Pieces subclasses vanilla Enum and has, at least from my point of view, very unexpected results. Pieces2 is based on IntEnum and behaves as might be expected.

import enum

class Pieces(enum.Enum):
    PAWN = 8
    ROOK = 2
    BISHOP = 2

print(2 == Pieces.ROOK) ## False WAT?! Always not equal to non enums
print(Pieces.ROOK == 2) ## False WAT?!
print(Pieces.BISHOP == Pieces.ROOK) ## True
print(Pieces.PAWN == Pieces.ROOK) ## False

class Pieces2(enum.IntEnum):
    PAWN = 8
    ROOK = 2
    BISHOP = 2

print(2 == Pieces2.ROOK) ## True
print(Pieces2.ROOK == 2) ## True
print(Pieces2.BISHOP == Pieces2.ROOK) ## True
print(Pieces2.PAWN == Pieces2.ROOK) ## False

It is easy to imagine this behaviour creating baffling bugs. Interesting.

Why SuperHELP for Python?

I created SuperHELP to make it easier for people to write good Python code. You can find the project at

SuperHELP logo

To summarise the rationale for SuperHELP I have thought of a few taglines:

SuperHELP – Python help that really helps!

SuperHELP – Help for Humans!

and even

SuperHELP – Make Python Pythonic!

Some context might help explain:

Python has secured its position in the top tier of programming languages and more people than ever are learning to write Python. But, let’s be honest, a lot of Python code being written is not what it could be. Even an elegant language like Python can be written badly or in a way that is hard to read or maintain.

To make it easier for people to write good Python we are already well-served by IDEs from IDLE upwards. People have easy access to style linters and IDEs clearly signal syntax errors and basic mistakes like unused variables. But wouldn’t it be great if people could check their code to see if there are better, more Pythonic ways of doing things? Or to learn more about basic language features and Python data structures than the standard help can offer?

That’s where SuperHELP can play a role.

So what exactly is SuperHELP? Basically it is an advice engine. SuperHELP reads a snippet of Python and provides advice, warnings, and basic information based on what it finds. For example, it might notice a function docstring is missing and show a template for adding one. Or identify the use of a named tuple and explain how to add docstrings to individual fields or the named tuple as a whole.

The intention is to make sure that everyone, from beginners upwards, learns something useful. Even an advanced Python programmer might not appreciate the benefits of using functools.wraps when creating their own decorator. Or an experienced Java programmer might not realise that Python properties are a much better option than getters and setters.

So how can people use SuperHELP? For most people, the easiest way will be to open a binder web notebook and enter their code there.


Of course, because SuperHELP is a pip package it can be installed alongside Python on a machine and used directly from the terminal e.g.

shelp --code "people = ['Tomas', 'Sal']" --output html --detail-level Main

If the output chosen is html (the default) output looks like:

And if –output cli (command line interface i.e. terminal or console) is selected, output looks like:

In all likelihood, there will be other ways of making SuperHELP advice more readily available – probably through integration with other platforms and processes.

SuperHELP needs your help:

  • If you have any ideas, or the ability to help in some way, please contact me at
  • Spread the word about SuperHELP through your social networks.