Skip to content

Conversation

@dbhatman
Copy link
Contributor

@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

_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
Contributor 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