Skip to content

Commit

Permalink
Detect Pydantic 2.10 models
Browse files Browse the repository at this point in the history
Signed-off-by: Emanuele Giaquinta <[email protected]>
  • Loading branch information
exg committed Nov 22, 2024
1 parent 762792a commit bddfd9b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/serialize/serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ pub fn pyobject_to_obtype_unlikely(obj: *mut pyo3::ffi::PyObject, opts: Opt) ->
ObType::NumpyArray
} else if opts & SERIALIZE_PYDANTIC != 0
&& (pydict_contains!(ob_type, PYDANTIC_FIELDS_STR)
|| pydict_contains!(ob_type, PYDANTIC2_FIELDS_STR))
|| pydict_contains!(ob_type, PYDANTIC2_VALIDATOR_STR))
{
ObType::Pydantic
} else if is_type!(ob_type, EXT_TYPE) {
Expand Down
6 changes: 3 additions & 3 deletions src/typeref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub static mut DICT_STR: *mut PyObject = null_mut();
pub static mut DATACLASS_FIELDS_STR: *mut PyObject = null_mut();
pub static mut SLOTS_STR: *mut PyObject = null_mut();
pub static mut PYDANTIC_FIELDS_STR: *mut PyObject = null_mut();
pub static mut PYDANTIC2_FIELDS_STR: *mut PyObject = null_mut();
pub static mut PYDANTIC2_VALIDATOR_STR: *mut PyObject = null_mut();
pub static mut FIELD_TYPE_STR: *mut PyObject = null_mut();
pub static mut ARRAY_STRUCT_STR: *mut PyObject = null_mut();
pub static mut DTYPE_STR: *mut PyObject = null_mut();
Expand Down Expand Up @@ -144,8 +144,8 @@ pub fn init_typerefs() {
PyUnicode_InternFromString("__dataclass_fields__\0".as_ptr() as *const c_char);
SLOTS_STR = PyUnicode_InternFromString("__slots__\0".as_ptr() as *const c_char);
PYDANTIC_FIELDS_STR = PyUnicode_InternFromString("__fields__\0".as_ptr() as *const c_char);
PYDANTIC2_FIELDS_STR =
PyUnicode_InternFromString("model_fields\0".as_ptr() as *const c_char);
PYDANTIC2_VALIDATOR_STR =
PyUnicode_InternFromString("__pydantic_validator__\0".as_ptr() as *const c_char);
FIELD_TYPE_STR = PyUnicode_InternFromString("_field_type\0".as_ptr() as *const c_char);
ARRAY_STRUCT_STR =
PyUnicode_InternFromString("__array_struct__\0".as_ptr() as *const c_char);
Expand Down

0 comments on commit bddfd9b

Please sign in to comment.