Skip to content

mypy is unable to narrow a union type that includes a StrEnum subclass and a Literal #20915

@exg

Description

@exg

Bug Report

As per the title, see the gist for an example. The issue does not occur when using Enum instead of StrEnum.

To Reproduce

https://mypy-play.net/?gist=cf9926c276e8fe0f48d7d20b7ebf2b6e

Expected Behavior

The output should be

main.py:12: note: Revealed type is "Literal['none']"
main.py:14: note: Revealed type is "__main__.Color"

Actual Behavior

The output is

main.py:12: note: Revealed type is "__main__.Color | Literal['none']"
main.py:14: note: Revealed type is "__main__.Color | Literal['none']"

Your Environment

  • Mypy version used: 1.19.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions