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 typecheck with StrEnum #17162

Open
roganov opened this issue Apr 24, 2024 · 0 comments
Open

False-positive typecheck with StrEnum #17162

roganov opened this issue Apr 24, 2024 · 0 comments
Labels
bug mypy got something wrong

Comments

@roganov
Copy link

roganov commented Apr 24, 2024

Bug Report

When comparing a member of StrEnum to a string, it seems that Mypy assumes that the check is always False and does not type-check code under the condition.

To Reproduce
https://mypy-play.net/?mypy=latest&python=3.12&gist=f7c8364d301ada4067a9a6f515b9e161

import typing
import enum

class MyEnum(str, enum.Enum):
    A = 'a'

class MyEnum2(enum.StrEnum):
    A = 'a'

if MyEnum.A == 'a':
    1 + ''

if MyEnum2.A == 'a':
    1 + ''

Expected Behavior

Mypy should flag both 1 + '' expressions as type errors because these conditions evaluate to True in runtime.

Actual Behavior

Mypy does not report errors

Your Environment

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

No branches or pull requests

1 participant