Open
Description
Description
Right now Meta supports min_length
and max_length
, but those are mostly meaningless without first stripping out whitespace.
Currently, we have to do variations on this all over the place:
class Foo(Struct):
bar: Annotated[str, Meta(min_length=1, max_length=20)]
def __post_init__(self):
self.bar = self.bar.strip()
if len(self.bar) < 1:
raise ValueError('too short')
if len(self.bar) > 20:
raise ValueError('too long')
This is obviously bad because it repeats the length checks and adds a lot of boilerplate. Something like this would be much simpler:
class Foo(Struct):
bar: Annotated[str, Meta(min_length=1, max_length=20, strip_whitespace=True)]
Even without the length checks, having a built in way to strip whitespace would be very useful and cut down on boilerplate. Other than things like passwords and tokens we need to strip whitespace on every single string field on its way in.
Metadata
Metadata
Assignees
Labels
No labels