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

mypy types set of StrEnum as set of str #18380

Open
injust opened this issue Dec 30, 2024 · 1 comment
Open

mypy types set of StrEnum as set of str #18380

injust opened this issue Dec 30, 2024 · 1 comment
Labels

Comments

@injust
Copy link

injust commented Dec 30, 2024

Bug Report

mypy types a set of StrEnum as set[str].

To Reproduce

from enum import Enum, StrEnum

class Tag(Enum):
    pass

class StrTag(StrEnum):
    pass

reveal_type(set(Tag))  # note: Revealed type is "builtins.set[__main__.Tag]"
reveal_type(set(StrTag))  # note: Revealed type is "builtins.set[builtins.str]"

https://mypy-play.net/?mypy=latest&python=3.13&gist=237de7c0610830acd5a5104d18541e3e

Expected Behavior

mypy should type set(StrTag) as set[StrTag], not set[str].

Actual Behavior

main.py:10: note: Revealed type is "builtins.set[builtins.str]"

Your Environment

  • Mypy version used: 1.14.0
  • Python version used: 3.13
@injust injust added the bug mypy got something wrong label Dec 30, 2024
@sobolevn
Copy link
Member

sobolevn commented Jan 1, 2025

This happens because str is also Iterable and str is closer in the MRO than Enum. Adding def __iter__(self) -> Self: ... to StrEnum solves the issue. But, I am not sure that this is the correct / full fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants