We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Enum
Right now this code does not produce any issues in mypy:
import enum class First: def __new__(cls, val): return 1 class Second: def __new__(cls, val): return 2 class Some(First, Second, enum.Enum): # ok x = 1
But, in runtime it fails:
>>> import enum >>> >>> class First: ... def __new__(cls, val): ... return 1 ... >>> class Second: ... def __new__(cls, val): ... return 2 ... >>> class Some(First, Second, enum.Enum): ... x = 1 ... Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/sobolev/Desktop/cpython/Lib/enum.py", line 403, in __prepare__ member_type, first_enum = metacls._get_mixins_(cls, bases) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/sobolev/Desktop/cpython/Lib/enum.py", line 893, in _get_mixins_ member_type = _find_data_type(bases) or object ^^^^^^^^^^^^^^^^^^^^^^ File "/Users/sobolev/Desktop/cpython/Lib/enum.py", line 881, in _find_data_type raise TypeError('%r: too many data types: %r' % (class_name, data_types)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: 'Some': too many data types: {<class '__main__.Second'>, <class '__main__.First'>}
This happens because Enum can have only one extra subclass with __new__, because it is used to create new Enum members.
__new__
The text was updated successfully, but these errors were encountered:
Check Enum definition for invalid base classes (#12026)
1321e9e
Closes #11948
Successfully merging a pull request may close this issue.
Right now this code does not produce any issues in mypy:
But, in runtime it fails:
This happens because
Enum
can have only one extra subclass with__new__
, because it is used to create newEnum
members.The text was updated successfully, but these errors were encountered: