Skip to content

Confusing error message for a missing classmethod decorator #11791

Open
@wrobell

Description

@wrobell

Please consider

import typing as tp
import enum

@enum.unique
class ColorIndex(enum.IntEnum):
    BLACK = 0
    GREY = 1
    WHITE = 2

    def _missing_(cls, value: object) -> tp.Any:
        return ColorIndex.BLACK

then mypy shows very confusing error (both signatures, for the subclass and the superclass, are the same)

$ mypy t.py
t.py:10: error: Signature of "_missing_" incompatible with supertype "Enum"
t.py:10: note:      Superclass:
t.py:10: note:          def _missing_(cls, value: object) -> Any
t.py:10: note:      Subclass:
t.py:10: note:          def _missing_(cls, value: object) -> Any
Found 1 error in 1 file (checked 1 source file)

The real issue is that _missing_ should be decorated with classmethod.

Python 3.10.1, mypy 0.930.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions