Thanks to visit codestin.com
Credit goes to github.com

Skip to content

too many data types false negative in Enum #12262

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

Closed
sobolevn opened this issue Feb 28, 2022 · 0 comments · Fixed by #12260
Closed

too many data types false negative in Enum #12262

sobolevn opened this issue Feb 28, 2022 · 0 comments · Fixed by #12260
Assignees
Labels
bug mypy got something wrong topic-enum

Comments

@sobolevn
Copy link
Member

import enum

class First:
    def __new__(cls, val):
        pass

class Second:
    def __new__(cls, val):
        pass

class Correct(First, enum.Enum):
    pass

class Wrong(Second, Correct):
    pass

This code does not produce any mypy warnings, but after #12026 it should.

Runtime raises:

Traceback (most recent call last):
  File "/Users/sobolev/Desktop/mypy/out/ex.py", line 14, in <module>
    class Wrong(Second, Correct):
  File "/Users/sobolev/.pyenv/versions/3.10.0/lib/python3.10/enum.py", line 172, in __prepare__
    member_type, first_enum = metacls._get_mixins_(cls, bases)
  File "/Users/sobolev/.pyenv/versions/3.10.0/lib/python3.10/enum.py", line 613, in _get_mixins_
    member_type = _find_data_type(bases) or object
  File "/Users/sobolev/.pyenv/versions/3.10.0/lib/python3.10/enum.py", line 601, in _find_data_type
    raise TypeError('%r: too many data types: %r' % (class_name, data_types))
TypeError: 'Wrong': too many data types: [<class '__main__.Second'>, <class '__main__.First'>]

PR is in the works.

@sobolevn sobolevn added bug mypy got something wrong topic-enum labels Feb 28, 2022
@sobolevn sobolevn self-assigned this Feb 28, 2022
JukkaL pushed a commit that referenced this issue Feb 28, 2022
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

Successfully merging a pull request may close this issue.

1 participant