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
Simplified length limited string #2104
Comments
You can't really do this with typing in Python, I don't think. The issue here is that to parametrise ('subscribe') a class for type checkers, it needs to be made generic. But a generic type can only be parametrised with other types - |
Perhaps this would be possible/clean/generic with PR #2147 and FR #2129 (working prototype)?
|
@layday StrLimit doesn't need to be a class, it can be a subscribable object. @samuelcolvin If we want to support both upper and lower bounds, perhaps |
This should work now, although we need to add
We had this in The point with this feature is to keep it simple and cover the most common case which is having an upper length limit - e.g. to be equivalent-to/compatible-with |
I don't think this is necessary any more. |
I often want
constr(max_length=XXX, strip_whitespace=True)
. Could we add a shortcut for this that worked better with mypy?E.g. something like
This would be equivalent to
constr(max_length=63, strip_whitespace=True)
, e.g a field with a max length of63
, no min limit,strip_whitespace
enabled.The name
StrLimit
is debatable. I think usingConStr
might be confusing, but perhaps would make more sense?We could also allow
StrLimit[10, 63]
which would be equivalent toconstr(min_length=10, max_length=63, strip_whitespace=True)
. However this would not be very pythonic in that the first argument meaning would change. Also I find myself wanting this very rarely.thoughts?
The text was updated successfully, but these errors were encountered: