Skip to content

Commit 741961c

Browse files
authored
refactor LookupKey logic to reduce redundancy (#1635)
1 parent 7da4798 commit 741961c

File tree

4 files changed

+215
-184
lines changed

4 files changed

+215
-184
lines changed

src/common/union.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use pyo3::{PyTraverseError, PyVisit};
44
use crate::lookup_key::LookupKey;
55
use crate::py_gc::PyGcTraverse;
66

7-
#[derive(Debug, Clone)]
7+
#[derive(Debug)]
88
pub enum Discriminator {
99
/// use `LookupKey` to find the tag, same as we do to find values in typed_dict aliases
1010
LookupKey(LookupKey),

src/errors/location.rs

-27
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ use pyo3::types::{PyList, PyTuple};
88
use serde::ser::SerializeSeq;
99
use serde::{Serialize, Serializer};
1010

11-
use crate::lookup_key::{LookupPath, PathItem};
12-
1311
/// Used to store individual items of the error location, e.g. a string for key/field names
1412
/// or a number for array indices.
1513
#[derive(Clone, Eq, PartialEq, IntoPyObjectRef)]
@@ -71,20 +69,6 @@ impl From<usize> for LocItem {
7169
}
7270
}
7371

74-
/// eventually it might be good to combine PathItem and LocItem
75-
impl From<PathItem> for LocItem {
76-
fn from(path_item: PathItem) -> Self {
77-
match path_item {
78-
PathItem::S(s, _) => s.into(),
79-
PathItem::Pos(val) => val.into(),
80-
PathItem::Neg(val) => {
81-
let neg_value = -(val as i64);
82-
neg_value.into()
83-
}
84-
}
85-
}
86-
}
87-
8872
impl Serialize for LocItem {
8973
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
9074
where
@@ -137,17 +121,6 @@ impl<'py> IntoPyObject<'py> for &'_ Location {
137121
}
138122
}
139123

140-
impl From<&LookupPath> for Location {
141-
fn from(lookup_path: &LookupPath) -> Self {
142-
let v = lookup_path
143-
.iter()
144-
.rev()
145-
.map(|path_item| path_item.clone().into())
146-
.collect();
147-
Self::List(v)
148-
}
149-
}
150-
151124
impl fmt::Display for Location {
152125
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
153126
match self {

src/errors/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mod validation_exception;
77
mod value_exception;
88

99
pub use self::line_error::{InputValue, ToErrorValue, ValError, ValLineError, ValResult};
10-
pub use self::location::LocItem;
10+
pub use self::location::{LocItem, Location};
1111
pub use self::types::{list_all_errors, ErrorType, ErrorTypeDefaults, Number};
1212
pub use self::validation_exception::{PyLineError, ValidationError};
1313
pub use self::value_exception::{PydanticCustomError, PydanticKnownError, PydanticOmit, PydanticUseDefault};

0 commit comments

Comments
 (0)