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

Pyautoscoper type validator #183

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

NicerNewerCar
Copy link
Contributor

@NicerNewerCar NicerNewerCar requested a review from jcfr August 2, 2023 17:55
@jcfr
Copy link
Contributor

jcfr commented Aug 7, 2023

Before adding validation, I suggest to add the missing annotation types by fixing the errors reported after enabling the ANN checks associated with ruff linting introduced in:

@NicerNewerCar NicerNewerCar force-pushed the pyautoscoper-type-validator branch 2 times, most recently from 76657de to d31db78 Compare August 8, 2023 13:58
@NicerNewerCar
Copy link
Contributor Author

Before adding validation, I suggest to add the missing annotation types by fixing the errors reported after enabling the ANN checks associated with ruff linting introduced in:

See #192

@jcfr jcfr force-pushed the pyautoscoper-type-validator branch from d31db78 to b99a31b Compare August 9, 2023 22:09
@jcfr jcfr force-pushed the pyautoscoper-type-validator branch from b99a31b to d03c892 Compare August 9, 2023 22:32
@jcfr
Copy link
Contributor

jcfr commented Aug 9, 2023

Relevant documentation:

@jcfr
Copy link
Contributor

jcfr commented Aug 9, 2023

We should also look into typeguard. See https://typeguard.readthedocs.io/en/latest/extending.html

It seems like we could specify custom types as annotation and have these used at runtime when the function is called.

Also relevant:

@NicerNewerCar
Copy link
Contributor Author

@jcfr The only errors in ruff now are a couple of ANN401 Dynamically typed expressions (typing.Any) are disallowed in value related to the any typing within the abstract Validator class:

class Validator(ABC):
"""Abstract base class for validators."""
def __set_name__(self, owner: type[object], name: str) -> None:
self.private_name = f"_{name}"
def __get__(self, obj: object, objtype: type[object] | None = None) -> Any:
return getattr(obj, self.private_name)
def __set__(self, obj: object, value: Any) -> None:
self.validate(value)
setattr(obj, self.private_name, value)
@abstractmethod
def validate(self, value: Any) -> None:
"""Validate the value."""
pass

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.

Improve robustness of PyAutoscoper introducing validator
2 participants