diff --git a/src/serializers/infer.rs b/src/serializers/infer.rs index bdfa74b52..a188f6f60 100644 --- a/src/serializers/infer.rs +++ b/src/serializers/infer.rs @@ -285,8 +285,7 @@ pub(crate) fn infer_to_python_known( } ObType::Complex => { let v = value.downcast::()?; - let complex_str = type_serializers::complex::complex_to_str(v); - complex_str.into_py(py) + v.into_py(py) } ObType::Unknown => { if let Some(fallback) = extra.fallback { diff --git a/tests/serializers/test_complex.py b/tests/serializers/test_complex.py index e7c98246a..2805ab3bd 100644 --- a/tests/serializers/test_complex.py +++ b/tests/serializers/test_complex.py @@ -37,3 +37,9 @@ def test_complex_json(value, expected): assert math.isnan(c.real) else: assert c.imag == value.imag + + +def test_complex_inference() -> None: + s = SchemaSerializer(core_schema.any_schema()) + assert s.to_python(1 + 2j) == 1 + 2j + assert s.to_json(1 + 2j) == b'"1+2j"'