Closed keithasaurus closed 1 year ago
Note that annotated-types is similar. Probably not exactly the same. Should look into
Sounds like Annotated is not really supported by plugins yet. https://github.com/python/mypy/issues/12619.
For now, the path that might make the most sense is to allow:
@validate_signature
def some_func(a: int, b: Annotated[str, StringValidator(MinLength(20))]) -> str:
...
Where int becomes a regular IntValidator
and the Annotated
StringValidator
is used for the second arg.
This requires a few changes, since presumably we want function signature checks to be exact (not coerced):
Motivation
A natural extension of
Predicate
s is to retain some vestige of them on validated types. Then we can do things likeImplementation
Presumably this is accomplished through
typing.Annotated
types. It would change the way we useAnnotated
. Breaking?I think a plugin would be needed for Mypy to accomplish this.
Questions
Annotated[str, MinLength(30)]
is allowed whenAnnotated[str, MinLength(20)]
is specified on a parameter?Predicate
s we'd be able to easily support?Predicate
arithmetic on their ownPredicate
s?