File tree 2 files changed +17
-0
lines changed
2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change 6
6
import enum
7
7
from json import JSONEncoder
8
8
from typing import Any
9
+ import typing
9
10
from uuid import UUID
10
11
from collections .abc import Sequence
11
12
from langfuse .api .core import serialize_datetime
@@ -107,6 +108,10 @@ def default(self, obj: Any):
107
108
if isinstance (obj , Sequence ):
108
109
return [self .default (item ) for item in obj ]
109
110
111
+ # Check if obj is a type or a generic alias
112
+ if isinstance (obj , type ) or typing .get_origin (obj ) is not None :
113
+ return f"<{ obj .__name__ } >"
114
+
110
115
if hasattr (obj , "__slots__" ):
111
116
return self .default (
112
117
{slot : getattr (obj , slot , None ) for slot in obj .__slots__ }
Original file line number Diff line number Diff line change 1
1
from datetime import datetime , date , timezone
2
+ import typing
2
3
from uuid import UUID
3
4
from enum import Enum
4
5
from dataclasses import dataclass
@@ -182,6 +183,17 @@ def __init__(self):
182
183
assert json .loads (serializer .encode (obj )) == {"field" : "value" }
183
184
184
185
186
+ def test_slots_types ():
187
+ class SlotClass :
188
+ def __init__ (self ):
189
+ self .something = typing .Sequence [int ]
190
+
191
+ obj = SlotClass ()
192
+
193
+ serializer = EventSerializer ()
194
+ assert json .loads (serializer .encode (obj )) == {"something" : "<Sequence>" }
195
+
196
+
185
197
def test_numpy_float32 ():
186
198
import numpy as np
187
199
You can’t perform that action at this time.
0 commit comments