Skip to content

Iteration over a Enum fails to typecheck if it's the Flag subclass #17858

Closed
@Quasar6X

Description

@Quasar6X

Bug Report

Mypy fails to determine the correct type when iterating over enum.Flag. The example uses reduce from functools. The corresponding typeshed definition for reduce looks correct to me.
Maybe related to #2305

To Reproduce

https://mypy-play.net/?mypy=master&python=3.12&flags=strict&gist=55eabf60ba0d43875271aa8438f04443

Actual Behavior

main.py:6: error: Incompatible return value type (got "object", expected "Flag")  [return-value]
main.py:6: error: Unsupported left operand type for | ("object")  [operator]
Found 2 errors in 1 file (checked 1 source file)

Your Environment

I've provided the mypy-play.net link but my environment looked like the following:

  • Mypy version used: 1.11.2
  • Mypy command-line flags: None
  • Mypy configuration options from pyproject.toml:
[tool.mypy]
# Maximum strictness level
strict = true
warn_unused_configs = true
enable_error_code = [
    "truthy-bool",
]
enable_incomplete_feature = "NewGenericSyntax"
  • Python version used: 3.12.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions