File tree 2 files changed +10
-0
lines changed
2 files changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -333,6 +333,7 @@ fn is_dataclass(op_value: Option<&PyAny>) -> bool {
333
333
value
334
334
. hasattr ( intern ! ( value. py( ) , "__dataclass_fields__" ) )
335
335
. unwrap_or ( false )
336
+ && !value. is_instance_of :: < PyType > ( )
336
337
} else {
337
338
false
338
339
}
@@ -343,6 +344,7 @@ fn is_pydantic_serializable(op_value: Option<&PyAny>) -> bool {
343
344
value
344
345
. hasattr ( intern ! ( value. py( ) , "__pydantic_serializer__" ) )
345
346
. unwrap_or ( false )
347
+ && !value. is_instance_of :: < PyType > ( )
346
348
} else {
347
349
false
348
350
}
Original file line number Diff line number Diff line change @@ -505,6 +505,14 @@ class Foo:
505
505
assert s .to_python (Foo (a = 'hello' , b = b'more' ), exclude = {'a' }) == IsStrictDict ()
506
506
assert s .to_json (Foo (a = 'hello' , b = b'more' ), exclude = {'a' }) == b'{}'
507
507
508
+ assert s .to_python (Foo ) == Foo
509
+ with pytest .raises (PydanticSerializationError , match = r"Unable to serialize unknown type: <class 'type'>" ):
510
+ s .to_python (Foo , mode = 'json' )
511
+ with pytest .raises (PydanticSerializationError , match = r"Unable to serialize unknown type: <class 'type'>" ):
512
+ s .to_json (Foo )
513
+ assert s .to_python (Foo , mode = 'json' , fallback = lambda x : x .__name__ ) == 'Foo'
514
+ assert s .to_json (Foo , fallback = lambda x : x .__name__ ) == b'"Foo"'
515
+
508
516
509
517
def test_dataclass_classvar (any_serializer ):
510
518
@dataclasses .dataclass
You can’t perform that action at this time.
0 commit comments