Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive "Method must have at least one argument" with @enum.member #18720

Open
sterliakov opened this issue Feb 22, 2025 · 0 comments
Open
Labels
bug mypy got something wrong topic-enum topic-runtime-semantics mypy doesn't model runtime semantics correctly

Comments

@sterliakov
Copy link
Collaborator

sterliakov commented Feb 22, 2025

Bug Report

enum.member-decorated functions become enum members and do not undergo self binding, similar to static methods. The repro snippet can be run with python 3.11 and newer to confirm.

To Reproduce

playground

from enum import Enum, member
from typing import reveal_type

class E(Enum):
    @member
    def A() -> int:
        return 1

assert E.A.value() == 1
reveal_type(E.A)
reveal_type(E.A.value)

Expected Behavior

Green output.

Actual Behavior

main.py:6: error: Method must have at least one argument. Did you forget the "self" argument?  [misc]
main.py:10: note: Revealed type is "enum.member[def () -> builtins.int]"
main.py:11: note: Revealed type is "def () -> builtins.int"

Your Environment

  • Mypy version used: 1.15.0 and current master
  • Mypy command-line flags: N/A
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: 3.12
@sterliakov sterliakov added bug mypy got something wrong topic-enum topic-runtime-semantics mypy doesn't model runtime semantics correctly labels Feb 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-enum topic-runtime-semantics mypy doesn't model runtime semantics correctly
Projects
None yet
Development

No branches or pull requests

1 participant