Skip to content

refactor LookupKey logic to reduce redundancy #1635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 13, 2025
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
2 changes: 1 addition & 1 deletion src/common/union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use pyo3::{PyTraverseError, PyVisit};
use crate::lookup_key::LookupKey;
use crate::py_gc::PyGcTraverse;

#[derive(Debug, Clone)]
#[derive(Debug)]
pub enum Discriminator {
/// use `LookupKey` to find the tag, same as we do to find values in typed_dict aliases
LookupKey(LookupKey),
Expand Down
27 changes: 0 additions & 27 deletions src/errors/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use pyo3::types::{PyList, PyTuple};
use serde::ser::SerializeSeq;
use serde::{Serialize, Serializer};

use crate::lookup_key::{LookupPath, PathItem};

/// Used to store individual items of the error location, e.g. a string for key/field names
/// or a number for array indices.
#[derive(Clone, Eq, PartialEq, IntoPyObjectRef)]
Expand Down Expand Up @@ -71,20 +69,6 @@ impl From<usize> for LocItem {
}
}

/// eventually it might be good to combine PathItem and LocItem
impl From<PathItem> for LocItem {
fn from(path_item: PathItem) -> Self {
match path_item {
PathItem::S(s, _) => s.into(),
PathItem::Pos(val) => val.into(),
PathItem::Neg(val) => {
let neg_value = -(val as i64);
neg_value.into()
}
}
}
}

impl Serialize for LocItem {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand Down Expand Up @@ -137,17 +121,6 @@ impl<'py> IntoPyObject<'py> for &'_ Location {
}
}

impl From<&LookupPath> for Location {
fn from(lookup_path: &LookupPath) -> Self {
let v = lookup_path
.iter()
.rev()
.map(|path_item| path_item.clone().into())
.collect();
Self::List(v)
}
}

impl fmt::Display for Location {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Expand Down
2 changes: 1 addition & 1 deletion src/errors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod validation_exception;
mod value_exception;

pub use self::line_error::{InputValue, ToErrorValue, ValError, ValLineError, ValResult};
pub use self::location::LocItem;
pub use self::location::{LocItem, Location};
pub use self::types::{list_all_errors, ErrorType, ErrorTypeDefaults, Number};
pub use self::validation_exception::{PyLineError, ValidationError};
pub use self::value_exception::{PydanticCustomError, PydanticKnownError, PydanticOmit, PydanticUseDefault};
Expand Down
Loading
Loading