|
1 | 1 | use std::borrow::Cow;
|
2 | 2 |
|
| 3 | +use num_bigint::BigInt; |
3 | 4 | use pyo3::exceptions::PyTypeError;
|
4 | 5 | use pyo3::intern;
|
5 | 6 | use pyo3::prelude::*;
|
@@ -44,7 +45,6 @@ pub(crate) fn infer_to_python_known(
|
44 | 45 | mut extra: &Extra,
|
45 | 46 | ) -> PyResult<PyObject> {
|
46 | 47 | let py = value.py();
|
47 |
| - |
48 | 48 | let mode = extra.mode;
|
49 | 49 | let mut guard = match extra.recursion_guard(value, INFER_DEF_REF_ID) {
|
50 | 50 | Ok(v) => v,
|
@@ -110,16 +110,20 @@ pub(crate) fn infer_to_python_known(
|
110 | 110 | );
|
111 | 111 | serializer.serializer.to_python(value, include, exclude, &extra)
|
112 | 112 | };
|
113 |
| - |
114 | 113 | let value = match extra.mode {
|
115 | 114 | SerMode::Json => match ob_type {
|
116 | 115 | // `bool` and `None` can't be subclasses, `ObType::Int`, `ObType::Float`, `ObType::Str` refer to exact types
|
117 | 116 | ObType::None | ObType::Bool | ObType::Int | ObType::Str => value.into_py(py),
|
118 | 117 | // have to do this to make sure subclasses of for example str are upcast to `str`
|
119 |
| - ObType::IntSubclass => match extract_i64(value) { |
120 |
| - Some(v) => v.into_py(py), |
121 |
| - None => return py_err!(PyTypeError; "expected int, got {}", safe_repr(value)), |
122 |
| - }, |
| 118 | + ObType::IntSubclass => { |
| 119 | + if let Some(v) = extract_i64(value) { |
| 120 | + v.into_py(py) |
| 121 | + } else if let Ok(b) = value.extract::<BigInt>() { |
| 122 | + b.into_py(py) |
| 123 | + } else { |
| 124 | + return py_err!(PyTypeError; "Expected int, got {}", safe_repr(value)); |
| 125 | + } |
| 126 | + } |
123 | 127 | ObType::Float | ObType::FloatSubclass => {
|
124 | 128 | let v = value.extract::<f64>()?;
|
125 | 129 | if (v.is_nan() || v.is_infinite()) && extra.config.inf_nan_mode == InfNanMode::Null {
|
|
0 commit comments