33from collections .abc import Iterable , Iterator , Mapping
44from dataclasses import asdict , dataclass , field , fields , is_dataclass
55from datetime import date
6+ from enum import Enum
67from typing import Any , Literal
78from xml .etree import ElementTree
89
@@ -26,8 +27,8 @@ def format_as_xml(
2627 This is useful since LLMs often find it easier to read semi-structured data (e.g. examples) as XML,
2728 rather than JSON etc.
2829
29- Supports: `str`, `bytes`, `bytearray`, `bool`, `int`, `float`, `date`, `datetime`, `Mapping `,
30- `Iterable`, `dataclass`, and `BaseModel`.
30+ Supports: `str`, `bytes`, `bytearray`, `bool`, `int`, `float`, `date`, `datetime`, `Enum `,
31+ `Mapping`, ` Iterable`, `dataclass`, and `BaseModel`.
3132
3233 Args:
3334 obj: Python Object to serialize to XML.
@@ -101,7 +102,7 @@ def _to_xml(self, value: Any, path: str, tag: str | None = None) -> ElementTree.
101102 element .text = value
102103 elif isinstance (value , bytes | bytearray ):
103104 element .text = value .decode (errors = 'ignore' )
104- elif isinstance (value , bool | int | float ):
105+ elif isinstance (value , bool | int | float | Enum ):
105106 element .text = str (value )
106107 elif isinstance (value , date ):
107108 element .text = value .isoformat ()
0 commit comments