@@ -187,6 +187,14 @@ def __get_pydantic_core_schema__(*args):
187
187
def __eq__ (self , other ):
188
188
raise NotImplementedError ("Can't be compared!" )
189
189
190
+ class NeqComparable (Incomparable ):
191
+ def __eq__ (self , other ):
192
+ return False
193
+
194
+ class EqComparable (Incomparable ):
195
+ def __eq__ (self , other ):
196
+ return True
197
+
190
198
v = SchemaSerializer (
191
199
core_schema .typed_dict_schema (
192
200
{
@@ -196,9 +204,13 @@ def __eq__(self, other):
196
204
}
197
205
)
198
206
)
199
- instance = Incomparable ()
200
- assert v .to_python ({'foo' : instance }, exclude_defaults = True )['foo' ] == [1 , 2 , 3 ]
201
- assert v .to_json ({'foo' : instance }, exclude_defaults = True ) == b'{"foo":[1,2,3]}'
207
+
208
+ assert v .to_python ({'foo' : Incomparable ()}, exclude_defaults = True )['foo' ] == [1 , 2 , 3 ]
209
+ assert v .to_json ({'foo' : Incomparable ()}, exclude_defaults = True ) == b'{"foo":[1,2,3]}'
210
+ assert v .to_python ({'foo' : NeqComparable ()}, exclude_defaults = True )['foo' ] == [1 , 2 , 3 ]
211
+ assert v .to_json ({'foo' : NeqComparable ()}, exclude_defaults = True ) == b'{"foo":[1,2,3]}'
212
+ assert v .to_python ({'foo' : EqComparable ()}, exclude_defaults = True ) == {}
213
+ assert v .to_json ({'foo' : EqComparable ()}, exclude_defaults = True ) == b'{}'
202
214
203
215
204
216
def test_function_plain_field_serializer_to_python ():
0 commit comments