3333from logfire .testing import TestExporter
3434
3535if sys .version_info >= (3 , 11 ): # pragma: no branch
36- from enum import StrEnum
36+ from enum import IntEnum , StrEnum
3737else : # pragma: no cover
3838
3939 class StrEnum (str , Enum ): ...
4040
41+ class IntEnum (int , Enum ): ...
42+
4143
4244pandas .set_option ('display.max_columns' , 10 )
4345pandas .set_option ('display.max_rows' , 20 )
@@ -1384,12 +1386,21 @@ def test_pydantic_root_model(exporter: TestExporter):
13841386 class Model (BaseModel ):
13851387 name : str
13861388
1389+ class Color (StrEnum ):
1390+ red = 'RED'
1391+
1392+ class Order (IntEnum ):
1393+ one = 1
1394+
13871395 RootWithModel = RootModel [Model ]
13881396 RootWithStr = RootModel [str ]
13891397 RootWithInt = RootModel [int ]
13901398 RootWithFloat = RootModel [float ]
13911399 RootWithBool = RootModel [bool ]
13921400 RootWithNone = RootModel [None ]
1401+ # enums (which are subclasses of their base types)
1402+ RootWithColor = RootModel [Color ]
1403+ RootWithOrder = RootModel [Order ]
13931404
13941405 model = Model (name = 'with_model' )
13951406 root_with_model = RootWithModel (root = model )
@@ -1398,6 +1409,8 @@ class Model(BaseModel):
13981409 root_with_float = RootWithFloat (2.0 )
13991410 root_with_bool = RootWithBool (False )
14001411 root_with_none = RootWithNone (None )
1412+ root_with_color = RootWithColor (Color .red )
1413+ root_with_order = RootWithOrder (Order .one )
14011414
14021415 logfire .info (
14031416 'hi' ,
@@ -1412,6 +1425,10 @@ class Model(BaseModel):
14121425 with_bool_inner = root_with_bool .root ,
14131426 with_none = root_with_none ,
14141427 with_none_inner = root_with_none .root ,
1428+ with_color = root_with_color ,
1429+ with_color_inner = root_with_color .root ,
1430+ with_order = root_with_order ,
1431+ with_order_inner = root_with_order .root ,
14151432 )
14161433
14171434 assert exporter .exported_spans_as_dict () == [
@@ -1442,7 +1459,11 @@ class Model(BaseModel):
14421459 'with_bool_inner' : False ,
14431460 'with_none' : 'null' ,
14441461 'with_none_inner' : 'null' ,
1445- 'logfire.json_schema' : '{"type":"object","properties":{"with_model":{"type":"object","title":"Model","x-python-datatype":"PydanticModel"},"with_str":{"type":"string","x-python-datatype":"string","title":"str"},"with_str_inner":{},"with_int":{"type":"integer","x-python-datatype":"number","title":"int"},"with_int_inner":{},"with_float":{"type":"number","x-python-datatype":"number","title":"float"},"with_float_inner":{},"with_bool":{"type":"boolean","x-python-datatype":null,"title":"bool"},"with_bool_inner":{},"with_none":{"type":"null"},"with_none_inner":{"type":"null"}}}' ,
1462+ 'with_color' : '"RED"' ,
1463+ 'with_color_inner' : '"RED"' ,
1464+ 'with_order' : '1' ,
1465+ 'with_order_inner' : '1' ,
1466+ 'logfire.json_schema' : '{"type":"object","properties":{"with_model":{"type":"object","title":"Model","x-python-datatype":"PydanticModel"},"with_str":{"type":"string","x-python-datatype":"string","title":"str"},"with_str_inner":{},"with_int":{"type":"integer","x-python-datatype":"number","title":"int"},"with_int_inner":{},"with_float":{"type":"number","x-python-datatype":"number","title":"float"},"with_float_inner":{},"with_bool":{"type":"boolean","x-python-datatype":null,"title":"bool"},"with_bool_inner":{},"with_none":{"type":"null"},"with_none_inner":{"type":"null"},"with_color":{"type":"string","x-python-datatype":"string","title":"Color"},"with_color_inner":{"type":"string","title":"Color","x-python-datatype":"Enum","enum":["RED"]},"with_order":{"type":"integer","x-python-datatype":"number","title":"Order"},"with_order_inner":{"type":"integer","title":"Order","x-python-datatype":"Enum","enum":[1]}}}' ,
14461467 },
14471468 }
14481469 ]
0 commit comments