We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Hi, thanks for this very useful library!
How do I flag attribute as required / mandatory?
I have this:
from traitlets import HasTraits, Unicode, TraitError, validate class MyS3Class(HasTraits): s3_bucket_name = Unicode() @validate('s3_bucket_name') def _check(self, proposal): raise TraitError("this doesn't trigger unless explicit non empty string is set")
But @validate('s3_bucket_name') doesn't get triggered if the user doesn't pass a value.
@validate('s3_bucket_name')
object = MyS3Class() # FAIL: doesn't trigger _check() object = MyS3Class(s3_bucket_name='') # FAIL: doesn't trigger _check() object = MyS3Class(s3_bucket_name=' ') # OK: properly triggers _check()
The text was updated successfully, but these errors were encountered:
For now I will "manually" trigger validations via:
class MyS3Class(HasTraits): def __init__(self, **kwargs): super(MyS3Class, self).__init__(**kwargs) self.s3_bucket_name = self.s3_bucket_name
Sorry, something went wrong.
@elgalu I would do the following:
class MyS3Class(HasTraits): s3_bucket_name = Unicode() @validate("s3_bucket_name") def _validate_s3_bucket_name(self, proposal): if not proposal.value: raise ValueError("S3 bucket name cannot be empty.") def __init__(self, s3_bucket_name, **kwargs): super().__init__(**kwargs) self.s3_bucket_name = s3_bucket_name
This both enforces the fact that the trait must be provided when instantiated and that it not be empty.
No branches or pull requests
Hi, thanks for this very useful library!
How do I flag attribute as required / mandatory?
I have this:
But
@validate('s3_bucket_name')
doesn't get triggered if the user doesn't pass a value.The text was updated successfully, but these errors were encountered: