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

Fix type-checking when using deprecated FieldValidationInfo #995

Merged
merged 1 commit into from Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions python/pydantic_core/core_schema.py
Expand Up @@ -3909,6 +3909,9 @@ def general_plain_validator_function(*args, **kwargs):
'FieldWrapValidatorFunction': WithInfoWrapValidatorFunction,
}

if TYPE_CHECKING:
FieldValidationInfo = ValidationInfo
Comment on lines +3912 to +3913
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW according to https://peps.python.org/pep-0702/#deprecation-of-modules-and-attributes there is no way to mark a module-level attribute as deprecated for typing purposes so this is the best we can do.



def __getattr__(attr_name: str) -> object:
new_attr = _deprecated_import_lookup.get(attr_name)
Expand Down
4 changes: 4 additions & 0 deletions tests/test_typing.py
Expand Up @@ -23,6 +23,10 @@ def foo(bar: str) -> None:
...


def validator_deprecated(value: Any, info: core_schema.FieldValidationInfo) -> None:
...
Comment on lines +26 to +27
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that we're running mypy on this. Does this fail before the source change? Might be worth pushing a commit without the source change to see CI fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think only Pyright runs on this file and it was failing after adding the test but before adding the fix. To my knowledge, mypy runs only stubtests.



def validator(value: Any, info: core_schema.ValidationInfo) -> None:
...

Expand Down