Skip to content
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

HasRequiredTraits class #419

Merged
merged 6 commits into from Dec 17, 2018
Merged

HasRequiredTraits class #419

merged 6 commits into from Dec 17, 2018

Conversation

jjenthought
Copy link
Contributor

From the docstring: This class builds on the functionality of HasStrictTraits and ensures that any object attribute with the metadata required=True must be passed as an argument on object initialization.

This came up as there were situations where a class had a few 'key' traits and the others were derived from them. It made sense to try and provide a more formal implementation of this pattern!

Things that I'm not sure about:

  • What else to test for
  • Whether using TraitError is appropriate (It doesn't really use any of the extra functionality TraitError provides)

@mdickinson
Copy link
Member

This is great; thank you!

What would be really useful would be to also have documentation on this. I think the right place for that would be in https://github.com/enthought/traits/blob/master/docs/source/traits_user_manual/advanced.rst

Would you be up to writing some documentation for this?

traits/has_traits.py Outdated Show resolved Hide resolved
@jjenthought
Copy link
Contributor Author

Definitely! For some reason when documentation got mentioned before I somehow parsed it as docstring. Completely forgetting about the actual documentation we write!

traits/has_traits.py Outdated Show resolved Hide resolved
@jjenthought
Copy link
Contributor Author

Ok, after some fighting with sphinx/restructured text this should be ready for re-review.

All required traits have to be provided as arguments on creating a new
instance::

>>> new_instance = RequiredTest(required_trait=13.0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please can you fix up the indentation to be consistent? (This code block is indented 3 spaces; the one above uses 4 spaces, and the ones below are 2 spaces. Pick one!)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, most of the rest of this document seems to use 4 spaces, so I'd go with that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like I need to sort out my tabs/spaces configs in atom!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, reST is weird, though. It encourages 3-space indents, so you tend to find a mix of 3-space and 4-space indents actual reST documentation.

'''''''''''''''''

This class builds on the functionality of HasStrictTraits and ensures
that any object attribute with `required=True` in its metadata must be passed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reST nit: use double backticks for code snippets. (Single backticks use the Sphinx default role, which isn't what you want here.)

HasRequiredTraits
'''''''''''''''''

This class builds on the functionality of HasStrictTraits and ensures
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might make sense to replace the somewhat vague "builds on" with something more precise. For example "This class inherits from HasStrictTraits [...]". Or even: "This subclass of HasStrictTraits ensures that ...".

@mdickinson
Copy link
Member

This is looking good; I've left a couple of nitpick-level comments.

Copy link
Member

@mdickinson mdickinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@corranwebster: want to do a final review before I merge?

@jjenthought jjenthought merged commit 1ab8ed1 into master Dec 17, 2018
@jjenthought jjenthought deleted the has-required-traits branch December 17, 2018 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants