Skip to content

Enum with a value named value assigned with auto gives incompatible types in assignment #20247

@nelsyeung

Description

@nelsyeung

Bug Report

Given an enum with a value named value assigned with enum.auto() incorrectly gives an assignment error.

To Reproduce

See https://mypy-play.net/?mypy=latest&python=3.10&gist=febab64ba10c1ebc532d7b6038194791

import enum
class A(enum.Enum):
    value = enum.auto()

Expected Behavior

No error.

Actual Behavior

main.py:3: error: Incompatible types in assignment (expression has type "auto", base class "Enum" defined the type as "int")  [assignment]
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: mypy 1.18.2 (compiled: yes)
  • Mypy command-line flags: mypy main.py
  • Mypy configuration options from mypy.ini (and other config files): nothing
  • Python version used: 3.10.18

Additional information

The value must be called value, if it's anything else, no error. E.g., this works:

class A(enum.Enum):
    v = enum.auto()

Multiple values also works:

class A(enum.Enum):
    value = enum.auto()
    v = enum.auto()

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions