@@ -169,19 +169,16 @@ def test_exclude_default():
169
169
assert v .to_json ({'foo' : 1 , 'bar' : b'[default]' }) == b'{"foo":1,"bar":"[default]"}'
170
170
assert v .to_json ({'foo' : 1 , 'bar' : b'[default]' }, exclude_defaults = True ) == b'{"foo":1}'
171
171
172
+
172
173
def test_exclude_incomparable_default ():
173
174
"""Values that can't be compared with eq are treated as not equal to the default"""
175
+
174
176
def ser_x (* args ):
175
- return [1 ,2 , 3 ]
177
+ return [1 , 2 , 3 ]
176
178
177
- cls_schema = core_schema .any_schema (
178
- serialization = core_schema .plain_serializer_function_ser_schema (
179
- ser_x
180
- )
181
- )
179
+ cls_schema = core_schema .any_schema (serialization = core_schema .plain_serializer_function_ser_schema (ser_x ))
182
180
183
181
class Incomparable :
184
-
185
182
__pydantic_serializer__ = SchemaSerializer (cls_schema )
186
183
187
184
def __get_pydantic_core_schema__ (* args ):
@@ -193,12 +190,14 @@ def __eq__(self, other):
193
190
v = SchemaSerializer (
194
191
core_schema .typed_dict_schema (
195
192
{
196
- 'foo' : core_schema .typed_dict_field (core_schema .with_default_schema (core_schema .any_schema (), default = None )),
193
+ 'foo' : core_schema .typed_dict_field (
194
+ core_schema .with_default_schema (core_schema .any_schema (), default = None )
195
+ ),
197
196
}
198
197
)
199
198
)
200
199
instance = Incomparable ()
201
- assert v .to_python ({'foo' : instance }, exclude_defaults = True )['foo' ] == [1 ,2 , 3 ]
200
+ assert v .to_python ({'foo' : instance }, exclude_defaults = True )['foo' ] == [1 , 2 , 3 ]
202
201
assert v .to_json ({'foo' : instance }, exclude_defaults = True ) == b'{"foo":[1,2,3]}'
203
202
204
203
0 commit comments