From f3c5714c47681264e1346c9ead3b7ad0f29e514e Mon Sep 17 00:00:00 2001 From: Sigurd Spieckermann <2206639+sisp@users.noreply.github.com> Date: Fri, 29 Sep 2023 16:08:13 +0200 Subject: [PATCH] Fix backwards compatibility of type-checking when using deprecated `FieldValidationInfo` (#995) --- python/pydantic_core/core_schema.py | 3 +++ tests/test_typing.py | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/python/pydantic_core/core_schema.py b/python/pydantic_core/core_schema.py index 2d7061ffd..347b93239 100644 --- a/python/pydantic_core/core_schema.py +++ b/python/pydantic_core/core_schema.py @@ -3909,6 +3909,9 @@ def general_plain_validator_function(*args, **kwargs): 'FieldWrapValidatorFunction': WithInfoWrapValidatorFunction, } +if TYPE_CHECKING: + FieldValidationInfo = ValidationInfo + def __getattr__(attr_name: str) -> object: new_attr = _deprecated_import_lookup.get(attr_name) diff --git a/tests/test_typing.py b/tests/test_typing.py index 0d527c619..dcd2f267a 100644 --- a/tests/test_typing.py +++ b/tests/test_typing.py @@ -23,6 +23,10 @@ def foo(bar: str) -> None: ... +def validator_deprecated(value: Any, info: core_schema.FieldValidationInfo) -> None: + ... + + def validator(value: Any, info: core_schema.ValidationInfo) -> None: ...