Question:In the relevant section of the Python
Enumdocumentation, it is mentioned that mix-in types can be used to ensure items belong to that type and act as objects of that type, like in the example:
The code I’m trying to write is
- Defining another class,
EnumFwfField, and using it as a mix-in, i.e.
but I get the same error as above;
class EnumFwfField(FwfField, Enum): pass class CnefeSchema(EnumFwfField, Enum): ...
- Setting the
Enumfields (in this example,
but then I get
class CnefeSchema(FwfField, Enum): state_code = FwfField("int", "Código da UF", 2) ...
Traceback (most recent call last): File "src/conf/schemas.py", line 25, in <module> class CnefeSchema(EnumFwfField, Enum): File "/usr/lib/python3.10/enum.py", line 298, in __new__ enum_member.__init__(*args) TypeError: FwfField.__init__() missing 2 required positional arguments: 'name' and 'width'
Answer:The issue you are having is because in your above code you have a
nameattribute in your
Enumwill not let you set a
Rename that field to something else, for example
'dname', and it should work.
(The error message in 3.11 is more informative.)
If you have better answer, please add a comment about this, thank you!