Skip to content

Commit 774fbbb

Browse files
authored
rename hide_input_in_errors -> hide_input on ValidationError (#641)
1 parent b09ec90 commit 774fbbb

File tree

3 files changed

+17
-28
lines changed

3 files changed

+17
-28
lines changed

pydantic_core/_pydantic_core.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class ValidationError(ValueError):
176176
title: str,
177177
errors: 'list[InitErrorDetails]',
178178
error_mode: Literal['python', 'json'] = 'python',
179-
hide_input_in_errors: bool = False,
179+
hide_input: bool = False,
180180
) -> ValidationError:
181181
"""
182182
Provisory constructor for a Validation Error.

src/errors/validation_exception.rs

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,16 @@ pub struct ValidationError {
3232
line_errors: Vec<PyLineError>,
3333
error_mode: ErrorMode,
3434
title: PyObject,
35-
hide_input_in_errors: bool,
35+
hide_input: bool,
3636
}
3737

3838
impl ValidationError {
39-
pub fn new(
40-
line_errors: Vec<PyLineError>,
41-
title: PyObject,
42-
error_mode: ErrorMode,
43-
hide_input_in_errors: bool,
44-
) -> Self {
39+
pub fn new(line_errors: Vec<PyLineError>, title: PyObject, error_mode: ErrorMode, hide_input: bool) -> Self {
4540
Self {
4641
line_errors,
4742
title,
4843
error_mode,
49-
hide_input_in_errors,
44+
hide_input,
5045
}
5146
}
5247

@@ -56,7 +51,7 @@ impl ValidationError {
5651
error_mode: ErrorMode,
5752
error: ValError,
5853
outer_location: Option<LocItem>,
59-
hide_input_in_errors: bool,
54+
hide_input: bool,
6055
) -> PyErr {
6156
match error {
6257
ValError::LineErrors(raw_errors) => {
@@ -67,7 +62,7 @@ impl ValidationError {
6762
.collect(),
6863
None => raw_errors.into_iter().map(|e| e.into_py(py)).collect(),
6964
};
70-
let validation_error = Self::new(line_errors, title, error_mode, hide_input_in_errors);
65+
let validation_error = Self::new(line_errors, title, error_mode, hide_input);
7166
match Py::new(py, validation_error) {
7267
Ok(err) => PyErr::from_value(err.into_ref(py)),
7368
Err(err) => err,
@@ -78,15 +73,9 @@ impl ValidationError {
7873
}
7974
}
8075

81-
pub fn display(&self, py: Python, prefix_override: Option<&'static str>, hide_input_in_errors: bool) -> String {
76+
pub fn display(&self, py: Python, prefix_override: Option<&'static str>, hide_input: bool) -> String {
8277
let url_prefix = get_url_prefix(py, include_url_env(py));
83-
let line_errors = pretty_py_line_errors(
84-
py,
85-
&self.error_mode,
86-
self.line_errors.iter(),
87-
url_prefix,
88-
hide_input_in_errors,
89-
);
78+
let line_errors = pretty_py_line_errors(py, &self.error_mode, self.line_errors.iter(), url_prefix, hide_input);
9079
if let Some(prefix) = prefix_override {
9180
format!("{prefix}\n{line_errors}")
9281
} else {
@@ -139,21 +128,21 @@ impl<'a> IntoPy<ValError<'a>> for ValidationError {
139128
#[pymethods]
140129
impl ValidationError {
141130
#[staticmethod]
142-
#[pyo3(signature = (title, line_errors, error_mode=None, hide_input_in_errors=false))]
131+
#[pyo3(signature = (title, line_errors, error_mode=None, hide_input=false))]
143132
fn from_exception_data(
144133
py: Python,
145134
title: PyObject,
146135
line_errors: &PyList,
147136
error_mode: Option<&str>,
148-
hide_input_in_errors: bool,
137+
hide_input: bool,
149138
) -> PyResult<Py<Self>> {
150139
Py::new(
151140
py,
152141
Self {
153142
line_errors: line_errors.iter().map(PyLineError::try_from).collect::<PyResult<_>>()?,
154143
title,
155144
error_mode: ErrorMode::try_from(error_mode)?,
156-
hide_input_in_errors,
145+
hide_input,
157146
},
158147
)
159148
}
@@ -228,7 +217,7 @@ impl ValidationError {
228217
}
229218

230219
fn __repr__(&self, py: Python) -> String {
231-
self.display(py, None, self.hide_input_in_errors)
220+
self.display(py, None, self.hide_input)
232221
}
233222

234223
fn __str__(&self, py: Python) -> String {
@@ -256,10 +245,10 @@ pub fn pretty_py_line_errors<'a>(
256245
error_mode: &ErrorMode,
257246
line_errors_iter: impl Iterator<Item = &'a PyLineError>,
258247
url_prefix: Option<&str>,
259-
hide_input_in_errors: bool,
248+
hide_input: bool,
260249
) -> String {
261250
line_errors_iter
262-
.map(|i| i.pretty(py, error_mode, url_prefix, hide_input_in_errors))
251+
.map(|i| i.pretty(py, error_mode, url_prefix, hide_input))
263252
.collect::<Result<Vec<_>, _>>()
264253
.unwrap_or_else(|err| vec![format!("[error formatting line errors: {err}]")])
265254
.join("\n")
@@ -373,7 +362,7 @@ impl PyLineError {
373362
py: Python,
374363
error_mode: &ErrorMode,
375364
url_prefix: Option<&str>,
376-
hide_input_in_errors: bool,
365+
hide_input: bool,
377366
) -> Result<String, fmt::Error> {
378367
let mut output = String::with_capacity(200);
379368
write!(output, "{}", self.location)?;
@@ -384,7 +373,7 @@ impl PyLineError {
384373
};
385374
write!(output, " {message} [type={}", self.error_type.type_string())?;
386375

387-
if !hide_input_in_errors {
376+
if !hide_input {
388377
let input_value = self.input_value.as_ref(py);
389378
let input_str = safe_repr(input_value);
390379
truncate_input_value!(output, input_str);

tests/test_errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ def test_raise_validation_error_hide_input(hide_input_in_errors, input_str):
575575
raise ValidationError.from_exception_data(
576576
'Foobar',
577577
[{'type': 'greater_than', 'loc': ('a', 2), 'input': 4, 'ctx': {'gt': 5}}],
578-
hide_input_in_errors=hide_input_in_errors,
578+
hide_input=hide_input_in_errors,
579579
)
580580

581581

0 commit comments

Comments
 (0)