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

Correct typing usage for Validators #1042

Merged
merged 1 commit into from
Oct 3, 2022
Merged

Conversation

dbhatman
Copy link
Collaborator

@dbhatman dbhatman commented Sep 29, 2022

The TypeVar usage was indicating that ALL validators available in _VALIDATORS would have the same type. This update only indicates that these validators are an instance of the ValidatorBase.

Pytype is currently erroring on master and this resolves those errors.


This change is Reviewable

The TypeVar usage was indicating that ALL validators available in _VALIDATORS would have the same type. This update only indicates that these validators are an instance of the ValidatorBase.
@dbhatman dbhatman changed the title Correct TypeVar usage for Validators Correct typing usage for Validators Sep 29, 2022
@@ -70,8 +70,7 @@ def __call__(self, value) -> bool:
"""Should validate value, returning a boolean result."""


_ValidatorT = TypeVar("_ValidatorT", bound=ValidatorBase)
_ValidatorFactoryT = Union[Type[_ValidatorT], Callable[..., _ValidatorT]]
_ValidatorFactoryT = Union[Callable[..., ValidatorBase]]
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't this change also mean that e.g. the Equals class (the class itself, not instances of it) can not be used anymore in _VALIDATORS?
I think at least Mypy does not agree that a class type doubles as a Callable[..., Classtype] even if you could argue that the class __init__ makes it behave that way.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Mypy does agree that Type[C] is a Callable[..., C]: python/mypy#1670

Also interestingly enough ABCs also match: python/mypy#12361

@dbhatman dbhatman merged commit 27c9382 into google:master Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants