You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A natural extension of Predicates is to retain some vestige of them on validated types. Then we can do things like
defreverse_long_string(x: Annotated[str, MinLength(20)]) ->Annotated[str, MinLength(20)]:
returnx[::-1]
validator=StringValidator(MinLength(4))
matchvalidator("abc123"):
caseValid(s):
reverse_long_string(s) # type error! Not long enoughcaseInvalid():
....
Implementation
Presumably this is accomplished through typing.Annotated types. It would change the way we use Annotated. Breaking?
I think a plugin would be needed for Mypy to accomplish this.
Questions
Can we develop the proper arithmetic in the type system to not have this feel cumbersome. For instance, can we make it so that Annotated[str, MinLength(30)] is allowed when Annotated[str, MinLength(20)] is specified on a parameter?
How large is the set of Predicates we'd be able to easily support?
Could there be a way for users to specify Predicate arithmetic on their own Predicates?
The text was updated successfully, but these errors were encountered:
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?The text was updated successfully, but these errors were encountered: