Skip to content

Commit

Permalink
docstring changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jjenthought committed Dec 11, 2018
1 parent c8ebd65 commit 1be9557
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions traits/has_traits.py
Expand Up @@ -3461,29 +3461,32 @@ class HasStrictTraits ( HasTraits ):

class HasRequiredTraits(HasStrictTraits):
""" This class builds on the functionality of HasStrictTraits and ensures
that any object attribute with `required=True` in its metadata must be
passed as an argument on object initialization.
that any object attribute with `required=True` in its metadata must be
passed as an argument on object initialization.
This can be useful in cases where an object has traits which are required
for it to function correctly.
Raises
------
TraitError
If a required trait is not passed as an argument
If a required trait is not passed as an argument.
Examples
--------
Usage
-----
A class with required traits:
>>> class RequiredTest(HasRequiredTraits):
>>> required_trait = Any(required=True)
>>> non_required_trait = Any()
... required_trait = Any(required=True)
... non_required_trait = Any()
Creating an instance of a HasRequiredTraits subclass:
Making an instance of a HasRequiredTraits class:
>>> test_instance = RequiredTest(required_trait=13, non_required_trait=11)
>>> test_instance2 = RequiredTest(required_trait=13)
Forgetting to specify a required trait:
>>> test_instance = RequiredTest(non_required_trait=11)
traits.trait_errors.TraitError: The following required traits were not
provided: required_trait.
Expand Down

0 comments on commit 1be9557

Please sign in to comment.