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

Incompatible return value type type[Enum] when returning a functional-style Enum #17147

Open
stefanhoelzl opened this issue Apr 21, 2024 · 0 comments
Labels
bug mypy got something wrong topic-enum

Comments

@stefanhoelzl
Copy link

Bug Report
When returning a functional-style Enum class from a function with the return type type[Enum] mypy reports an error.

When the created Enum class is assigned to a variable and the variable is return, mypy does not report an error.

To Reproduce

from enum import Enum

def direct_return() -> type[Enum]:
    return Enum("direct", {"a": 0})    # error: Incompatible return value type (got "Enum", expected "type[Enum]")  [return-value]

def indirect_return() -> type[Enum]:
    indirect = Enum("indirect", {"a": 0})
    return indirect                    # no error as expected

Gist URL
Playground URL

Expected Behavior

no mypy warnings

Actual Behavior

main.py:4: error: Incompatible return value type (got "Enum", expected "type[Enum]") [return-value]

Your Environment

  • Mypy version used: 1.9.0 and master on mypy-play.net
  • Mypy command-line flags: mypy-play.net defaults
  • Mypy configuration options from mypy.ini (and other config files): mypy-play.net defaults
  • Python version used: 3.12
@stefanhoelzl stefanhoelzl added the bug mypy got something wrong label Apr 21, 2024
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
Projects
None yet
Development

No branches or pull requests

2 participants