Skip to content

Commit 56b051d

Browse files
committed
fix enum related formatting bug in Python 3.10
1 parent a4ba84c commit 56b051d

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/dataclass_binder/_impl.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,13 @@ def format_toml_pair(key: str, value: object) -> str:
689689
def _to_toml_pair(value: object) -> tuple[str | None, Any]:
690690
"""Return a TOML-compatible suffix and value pair with the data from the given rich value object."""
691691
match value:
692+
# enums have to be checked before basic types because for instance
693+
# IntEnum is also of type int
694+
case Enum():
695+
if isinstance(value, ReprEnum):
696+
return None, value.value
697+
else:
698+
return None, value.name.lower()
692699
case str() | int() | float() | date() | time() | Path(): # note: 'bool' is a subclass of 'int'
693700
return None, value
694701
case timedelta():
@@ -718,11 +725,6 @@ def _to_toml_pair(value: object) -> tuple[str | None, Any]:
718725
return "-weeks", days // 7
719726
else:
720727
return "-days", days
721-
case Enum():
722-
if isinstance(value, ReprEnum):
723-
return None, value.value
724-
else:
725-
return None, value.name.lower()
726728
case ModuleType():
727729
return None, value.__name__
728730
case Mapping():

0 commit comments

Comments
 (0)