Skip to content
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

use full type names in errors #1342

Closed
wants to merge 3 commits into from
Closed
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/errors/validation_exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ impl PyLineError {
let input_str = safe_repr(input_value);
truncate_input_value!(output, &input_str.to_cow());

if let Ok(type_) = input_value.get_type().qualname() {
if let Ok(type_) = input_value.get_type().fully_qualified_name() {
write!(output, ", input_type={type_}")?;
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/emscripten_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ async function main() {
const pyodide = await loadPyodide();
const FS = pyodide.FS;
setupStreams(FS, pyodide._module.TTY);
FS.mkdir('/test_dir');
FS.mount(FS.filesystems.NODEFS, {root: path.join(root_dir, 'tests')}, '/test_dir');
FS.chdir('/test_dir');
FS.mkdir('/tests');
FS.mount(FS.filesystems.NODEFS, {root: path.join(root_dir, 'tests')}, '/tests');
FS.chdir('/tests');
await pyodide.loadPackage(['micropip', 'pytest']);
// language=python
errcode = await pyodide.runPythonAsync(`
Expand Down
2 changes: 1 addition & 1 deletion tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ def test_error_on_repr(pydantic_version):
assert str(exc_info.value) == (
'1 validation error for int\n'
' Input should be a valid integer '
'[type=int_type, input_value=<unprintable BadRepr object>, input_type=BadRepr]\n'
'[type=int_type, input_value=<unprintable BadRepr object>, input_type=tests.test_errors.BadRepr]\n'
f' For further information visit https://errors.pydantic.dev/{pydantic_version}/v/int_type'
)
assert exc_info.value.errors(include_url=False) == [
Expand Down
2 changes: 1 addition & 1 deletion tests/validators/test_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ def test_error_display(pydantic_version):
'1 validation error for arguments\n'
'b\n'
' Missing required argument [type=missing_argument, '
"input_value=ArgsKwargs((), {'a': 1}), input_type=ArgsKwargs]\n"
"input_value=ArgsKwargs((), {'a': 1}), input_type=pydantic_core._pydantic_core.ArgsKwargs]\n"
f' For further information visit https://errors.pydantic.dev/{pydantic_version}/v/missing_argument'
)
# insert_assert(exc_info.value.json(include_url=False))
Expand Down
10 changes: 6 additions & 4 deletions tests/validators/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,9 @@ def test_non_finite_json_values(py_and_json: PyAndJson, input_value, allow_inf_n
(
Decimal('nan'),
False,
Err("Input should be a finite number [type=finite_number, input_value=Decimal('NaN'), input_type=Decimal]"),
Err(
"Input should be a finite number [type=finite_number, input_value=Decimal('NaN'), input_type=decimal.Decimal]"
),
),
],
)
Expand All @@ -379,21 +381,21 @@ def test_non_finite_decimal_values(strict, input_value, allow_inf_nan, expected)
Decimal('+inf'),
False,
Err(
"Input should be a finite number [type=finite_number, input_value=Decimal('Infinity'), input_type=Decimal]"
"Input should be a finite number [type=finite_number, input_value=Decimal('Infinity'), input_type=decimal.Decimal]"
),
),
(
Decimal('-inf'),
True,
Err(
"Input should be greater than 0 [type=greater_than, input_value=Decimal('-Infinity'), input_type=Decimal]"
"Input should be greater than 0 [type=greater_than, input_value=Decimal('-Infinity'), input_type=decimal.Decimal]"
),
),
(
Decimal('-inf'),
False,
Err(
"Input should be a finite number [type=finite_number, input_value=Decimal('-Infinity'), input_type=Decimal]"
"Input should be a finite number [type=finite_number, input_value=Decimal('-Infinity'), input_type=decimal.Decimal]"
),
),
],
Expand Down
4 changes: 2 additions & 2 deletions tests/validators/test_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def test_int_py_and_json(py_and_json: PyAndJson, input_value, expected):
Decimal('1.001'),
Err(
'Input should be a valid integer, got a number with a fractional part '
"[type=int_from_float, input_value=Decimal('1.001'), input_type=Decimal]"
"[type=int_from_float, input_value=Decimal('1.001'), input_type=decimal.Decimal]"
),
id='decimal-remainder',
),
Expand Down Expand Up @@ -169,7 +169,7 @@ def test_int(input_value, expected):
Decimal('1.001'),
Err(
'Input should be a valid integer, got a number with a fractional part '
"[type=int_from_float, input_value=Decimal('1.001'), input_type=Decimal]"
"[type=int_from_float, input_value=Decimal('1.001'), input_type=decimal.Decimal]"
),
id='decimal-remainder',
),
Expand Down
4 changes: 3 additions & 1 deletion tests/validators/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ def test_str(py_and_json: PyAndJson, input_value, expected):
(123, Err('Input should be a valid string [type=string_type, input_value=123, input_type=int]')),
(
Decimal('123'),
Err("Input should be a valid string [type=string_type, input_value=Decimal('123'), input_type=Decimal]"),
Err(
"Input should be a valid string [type=string_type, input_value=Decimal('123'), input_type=decimal.Decimal]"
),
),
],
)
Expand Down
4 changes: 2 additions & 2 deletions wasm-preview/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ async function main() {
const pyodide = await loadPyodide();
const {FS} = pyodide;
setupStreams(FS, pyodide._module.TTY);
FS.mkdir('/test_dir');
FS.chdir('/test_dir');
FS.mkdir('/tests');
FS.chdir('/tests');
await pyodide.loadPackage(['micropip', 'pytest', 'numpy']);
if (pydantic_core_version < '2.0.0') await pyodide.loadPackage(['typing-extensions']);
await pyodide.runPythonAsync(python_code, {globals: pyodide.toPy({pydantic_core_version, tests_zip})});
Expand Down
Loading