1

I have this class for auto-name enums.

class AutoNameEnum(Enum):
    def _generate_next_value_(name, start, count, last_values):
        return name

This is taken straight from the Python documentation on enums.

Usage is like this

class Priority(AutoNameEnum):
    LOW = auto()
    HIGH = auto()

priority = Priority.LOW

This all works fine and mypy understands everything here. But when I try to put AutoNameEnum into a separate package I get an error. Specifically, this

from utilities import AutoNameEnum

class Priority(AutoNameEnum):
    LOW = auto()
    HIGH = auto()

priority = Priority.LOW

results in

Incompatible default for argument "priority" (default has type "auto", argument has type "Priority")

What does this mypy error mean, and why does it only happen when I import the class from a different package?

Kris Harper
  • 5,672
  • 8
  • 51
  • 96

1 Answers1

2

This actually had nothing to do with auto or Enum. I simply had to indicate that my package was typed by adding a file called py.typed to the root of the package. Without that, mypy did not scan the package for types.

Kris Harper
  • 5,672
  • 8
  • 51
  • 96