Skip to content

Commit 68f000d

Browse files
committed
rename
1 parent 6d68041 commit 68f000d

File tree

7 files changed

+11
-11
lines changed

7 files changed

+11
-11
lines changed

python/pydantic_core/core_schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3964,7 +3964,7 @@ def definition_reference_schema(
39643964
'no_such_attribute',
39653965
'json_invalid',
39663966
'json_type',
3967-
'cannot_validate_from_json',
3967+
'needs_python_object',
39683968
'recursion_loop',
39693969
'missing',
39703970
'frozen_field',

src/errors/types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ error_types! {
167167
error: {ctx_type: String, ctx_fn: field_from_context},
168168
},
169169
JsonType {},
170-
CannotValidateFromJson { method_name: {ctx_type: String, ctx_fn: field_from_context} },
170+
NeedsPythonObject { method_name: {ctx_type: String, ctx_fn: field_from_context} },
171171
// ---------------------
172172
// recursion error
173173
RecursionLoop {},
@@ -478,7 +478,7 @@ impl ErrorType {
478478
Self::NoSuchAttribute {..} => "Object has no attribute '{attribute}'",
479479
Self::JsonInvalid {..} => "Invalid JSON: {error}",
480480
Self::JsonType {..} => "JSON input should be string, bytes or bytearray",
481-
Self::CannotValidateFromJson {..} => "Cannot check `{method_name}` when validating from json, use a JsonOrPython validator instead",
481+
Self::NeedsPythonObject {..} => "Cannot check `{method_name}` when validating from json, use a JsonOrPython validator instead",
482482
Self::RecursionLoop {..} => "Recursion error - cyclic reference detected",
483483
Self::Missing {..} => "Field required",
484484
Self::FrozenField {..} => "Field is frozen",
@@ -628,7 +628,7 @@ impl ErrorType {
628628
match self {
629629
Self::NoSuchAttribute { attribute, .. } => render!(tmpl, attribute),
630630
Self::JsonInvalid { error, .. } => render!(tmpl, error),
631-
Self::CannotValidateFromJson { method_name, .. } => render!(tmpl, method_name),
631+
Self::NeedsPythonObject { method_name, .. } => render!(tmpl, method_name),
632632
Self::GetAttributeError { error, .. } => render!(tmpl, error),
633633
Self::ModelType { class_name, .. } => render!(tmpl, class_name),
634634
Self::DataclassType { class_name, .. } => render!(tmpl, class_name),

src/validators/is_instance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl Validator for IsInstanceValidator {
5757
let Some(obj) = input.as_python() else {
5858
let method_name = "isinstance".to_string();
5959
return Err(ValError::new(
60-
ErrorType::CannotValidateFromJson {
60+
ErrorType::NeedsPythonObject {
6161
context: None,
6262
method_name,
6363
},

src/validators/is_subclass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl Validator for IsSubclassValidator {
5252
let Some(obj) = input.as_python() else {
5353
let method_name = "issubclass".to_string();
5454
return Err(ValError::new(
55-
ErrorType::CannotValidateFromJson {
55+
ErrorType::NeedsPythonObject {
5656
context: None,
5757
method_name,
5858
},

tests/test_errors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def f(input_value, info):
258258
('json_invalid', 'Invalid JSON: foobar', {'error': 'foobar'}),
259259
('json_type', 'JSON input should be string, bytes or bytearray', None),
260260
(
261-
'cannot_validate_from_json',
261+
'needs_python_object',
262262
'Cannot check `isinstance` when validating from json, use a JsonOrPython validator instead',
263263
{'method_name': 'isinstance'},
264264
),
@@ -511,7 +511,7 @@ def test_all_errors():
511511
'example_context': None,
512512
},
513513
{
514-
'type': 'cannot_validate_from_json',
514+
'type': 'needs_python_object',
515515
'message_template_python': 'Cannot check `{method_name}` when validating from json, use a JsonOrPython validator instead',
516516
'example_message_python': 'Cannot check `` when validating from json, use a JsonOrPython validator instead',
517517
'example_context': {'method_name': ''},

tests/validators/test_is_instance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_validate_json() -> None:
2121
v = SchemaValidator({'type': 'is-instance', 'cls': Foo})
2222
with pytest.raises(ValidationError) as exc_info:
2323
v.validate_json('"foo"')
24-
assert exc_info.value.errors()[0]['type'] == 'cannot_validate_from_json'
24+
assert exc_info.value.errors()[0]['type'] == 'needs_python_object'
2525

2626

2727
def test_is_instance():
@@ -178,7 +178,7 @@ def test_is_instance_json_type_before_validator():
178178

179179
with pytest.raises(ValidationError) as exc_info:
180180
v.validate_json('null')
181-
assert exc_info.value.errors()[0]['type'] == 'cannot_validate_from_json'
181+
assert exc_info.value.errors()[0]['type'] == 'needs_python_object'
182182

183183
# now wrap in a before validator
184184
def set_type_to_int(input: None) -> type:

tests/validators/test_is_subclass.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,4 @@ def test_is_subclass_json() -> None:
8383
v = SchemaValidator(core_schema.is_subclass_schema(Foo))
8484
with pytest.raises(ValidationError) as exc_info:
8585
v.validate_json("'Foo'")
86-
assert exc_info.value.errors()[0]['type'] == 'cannot_validate_from_json'
86+
assert exc_info.value.errors()[0]['type'] == 'needs_python_object'

0 commit comments

Comments
 (0)