Skip to content

Commit afd23ee

Browse files
Fix serialization inference for complex types in python (#1549)
1 parent 1e5e899 commit afd23ee

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/serializers/infer.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,7 @@ pub(crate) fn infer_to_python_known(
285285
}
286286
ObType::Complex => {
287287
let v = value.downcast::<PyComplex>()?;
288-
let complex_str = type_serializers::complex::complex_to_str(v);
289-
complex_str.into_py(py)
288+
v.into_py(py)
290289
}
291290
ObType::Unknown => {
292291
if let Some(fallback) = extra.fallback {

tests/serializers/test_complex.py

+6
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,9 @@ def test_complex_json(value, expected):
3737
assert math.isnan(c.real)
3838
else:
3939
assert c.imag == value.imag
40+
41+
42+
def test_complex_inference() -> None:
43+
s = SchemaSerializer(core_schema.any_schema())
44+
assert s.to_python(1 + 2j) == 1 + 2j
45+
assert s.to_json(1 + 2j) == b'"1+2j"'

0 commit comments

Comments
 (0)