Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions src/errors/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl From<String> for LocItem {

impl From<&String> for LocItem {
fn from(s: &String) -> Self {
s.to_string().into()
s.clone().into()
}
}

Expand Down Expand Up @@ -87,22 +87,17 @@ impl Serialize for LocItem {
/// Note: location in List is stored in **REVERSE** so adding an "outer" item to location involves
/// pushing to the vec which is faster than inserting and shifting everything along.
/// Then when "using" location in `Display` and `ToPyObject` order has to be reversed
#[derive(Clone)]
#[derive(Clone, Default)]
#[cfg_attr(debug_assertions, derive(Debug))]
pub enum Location {
// no location, avoid creating an unnecessary vec
#[default]
Empty,
// store the in a vec of LocItems, Note: this is the REVERSE of location, see above
// we could perhaps use a smallvec or similar here, probably only worth it if we store a Cow in LocItem
List(Vec<LocItem>),
}

impl Default for Location {
fn default() -> Self {
Self::Empty
}
}

static EMPTY_TUPLE: PyOnceLock<Py<PyTuple>> = PyOnceLock::new();

impl<'py> IntoPyObject<'py> for &'_ Location {
Expand Down
6 changes: 3 additions & 3 deletions src/serializers/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,23 +191,23 @@ impl TemporalMode {

pub fn datetime_json_key<'py>(self, datetime: &Bound<'_, PyDateTime>) -> PyResult<Cow<'py, str>> {
match self {
Self::Iso8601 => Ok(datetime_to_string(datetime)?.to_string().into()),
Self::Iso8601 => Ok(datetime_to_string(datetime)?.into()),
Self::Seconds => Ok(datetime_to_seconds(datetime)?.to_string().into()),
Self::Milliseconds => Ok(datetime_to_milliseconds(datetime)?.to_string().into()),
}
}

pub fn date_json_key<'py>(self, date: &Bound<'_, PyDate>) -> PyResult<Cow<'py, str>> {
match self {
Self::Iso8601 => Ok(date_to_string(date)?.to_string().into()),
Self::Iso8601 => Ok(date_to_string(date)?.into()),
Self::Seconds => Ok(date_to_seconds(date)?.to_string().into()),
Self::Milliseconds => Ok(date_to_milliseconds(date)?.to_string().into()),
}
}

pub fn time_json_key<'py>(self, time: &Bound<'_, PyTime>) -> PyResult<Cow<'py, str>> {
match self {
Self::Iso8601 => Ok(time_to_string(time)?.to_string().into()),
Self::Iso8601 => Ok(time_to_string(time)?.into()),
Self::Seconds => Ok(time_to_seconds(time)?.to_string().into()),
Self::Milliseconds => Ok(time_to_milliseconds(time)?.to_string().into()),
}
Expand Down
2 changes: 1 addition & 1 deletion src/serializers/extra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ impl CollectWarnings {
return Ok(());
}

let formatted_warnings: Vec<String> = self.warnings.iter().map(|w| w.__repr__(py).to_string()).collect();
let formatted_warnings: Vec<String> = self.warnings.iter().map(|w| w.__repr__(py)).collect();

let message = format!("Pydantic serializer warnings:\n {}", formatted_warnings.join("\n "));
if self.mode == WarningsMode::Warn {
Expand Down
2 changes: 1 addition & 1 deletion src/serializers/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ pub(crate) fn infer_json_key_known<'a, 'py>(
}
ObType::MultiHostUrl => {
let py_url: PyMultiHostUrl = key.extract()?;
Ok(Cow::Owned(py_url.__str__(key.py()).to_string()))
Ok(Cow::Owned(py_url.__str__(key.py())))
}
ObType::Tuple => {
let mut key_build = super::type_serializers::tuple::KeyBuilder::new();
Expand Down
2 changes: 1 addition & 1 deletion src/validators/dataclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ impl Validator for DataclassArgsValidator {
return Err(ValError::new_with_loc(
ErrorTypeDefaults::FrozenField,
field_value,
field.name.to_string(),
&field.name,
));
}
// by using dict but removing the field in question, we match V1 behaviour
Expand Down
2 changes: 1 addition & 1 deletion src/validators/model_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ impl Validator for ModelFieldsValidator {
return Err(ValError::new_with_loc(
ErrorTypeDefaults::FrozenField,
field_value,
field.name.to_string(),
&field.name,
));
}

Expand Down
Loading