-
-
Notifications
You must be signed in to change notification settings - Fork 200
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
dynamically generate HasTraits class documentation #131
Conversation
c46c6ea
to
b9a2d30
Compare
@akhmerov I've never used |
It should be quite sufficient for Not sure what the proper thing is to do with the formatting; Perhaps the numpy docstring standard:
You can possibly omit class name from the appended docstring. Numpy often doesn't list defaults since these are apparent from call signatures, however this doesn't seem an option for traits. Should read-only traits be omitted from the doc? @minrk mentioned that there's a nontrivial decision to be made regarding subclassing. |
Signature manipulation: perhaps then do it optionally, checking for the interpreter version? |
I only looked into signature manipulation briefly, so I'll try to confirm, but I think the issue prior to 3.3 is that functions compile differently depending on signature. Given that, |
Oh, I just mean "rewrite the signature on 3.3, do nothing < 3.3". I cannot think of negative consequences of a less informative signature. |
Gotcha. In terms of doc formatting in |
Sorry, didn't get that. What exactly do you mean? What sort of confusion do you expect? Also a disclaimer I should have made earlier: I'm not a dev, just another guy with an opinion, and I'm not even sure if devs consider this reasonable to implement. |
So with traitlets having a class like this: class A(HasTraits):
i = Int()
a = A()
out = a.i
|
Based on my experience, I think having documentation in some capacity that describes what traits exist on the class would be helpful. At the moment, the only real way to understand what's going on is to look at the source. I'd have to think about how to implement it, but it should even be possible to include information on what static notifiers are associated with each trait providing more context for what the class does. |
Ah, my apologies, I was unclear. By |
574cdb0
to
8e50c54
Compare
I think I'll wait to work through signature manipulation until there's consensus on how I've implemented this so far. Until then, I think this pretty much covers documentation of ping @minrk @SylvainCorlay |
e647faa
to
47672e5
Compare
Is there anything missing in this PR? It's quite important in making |
c59c4ef
to
c181056
Compare
__init__
documentation081a58e
to
97897ba
Compare
@minrk now rebased and tests pass. In 92f87ec, the dynamic trait documentation is written to So depending on where we prefer the documentation to be I can either revert to 01adb49, or squash the commits. I think putting them in |
Sorry, I think this needs a rebase due to the revert of class_traits changes. |
# - - - - - - - - - - - - - - - - | ||
|
||
def trait_documentation(cls, name=None): | ||
"""Generate documentaiton for traits and event handlers on the class |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
documentation
@minrk I'm giving this an update. However it's still a work in progress. In general I'm making things more modular. This will make it easier to write import json
class DocLogEncoder(json.JSONEncoder):
def __init__(self, *a, **kw):
if kw.pop('pretty', True):
kw.update(sort_keys=True, indent=4)
super(DocLogEncoder, self).__init__(*a, **kw)
def default(self, obj):
return obj.content
class BaseClass(HasTraits):
foo = Int()
class SubClass(BaseClass):
# foo is documented (with added changes)
foo = Int(default_value=5, min=0, max=10)
# bar won't be documented by foo_logger
bar = Int()
foo_logger = hastraits_doclogger(BaseClass)
log_one = foo_logger(BaseClass)
log_two = foo_logger(SubClass)
dle = DocLogEncoder(pretty=True)
print(dle.encode(log_one))
print(dle.encode(log_two)) |
A first go at generating
TraitType
documentation inside theHasTraits.__init__
docstring.has a docstring that reads:
closes #130