Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python: make enums extend
IntEnum
, fix to_i
on invalid enum vals
Fix kaitai-io/kaitai_struct#815 Note: this actually fixes the `to_i` method on enum values in Construct as well, because `ConstructTranslator` inherits from `PythonTranslator` and doesn't override the `enumToInt` method. The previous `enumToInt` implementation (`s"${translate(v)}.value"`) didn't work in Construct at all, because Construct uses its own classes for enum values (as evidenced by our failing tests, these were `EnumInteger` and `EnumIntegerString`, apparently defined here: https://github.com/construct/construct/blob/3f3f30937bee74274147c6833137ad172fa62627/construct/core.py#L1865-L1883), which don't have any `.value` attribute. But as the Construct docs say about these classes (https://construct.readthedocs.io/en/latest/api/mappings.html#construct.Enum): > Returns an **integer-convertible** string (if mapping found) or an > integer (otherwise). ... so an enum value in Construct can be always converted to an integer using the built-in `int()` function just fine.
- Loading branch information