-
-
Notifications
You must be signed in to change notification settings - Fork 161
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
BUG: Defer to autodoc for signatures #221
Conversation
Why do you think this needs to be an option? |
I don't. I just don't know if you want to defer this to autodoc. (More of an architecture question.) Could just delete all that code in that case. Throwing out ideas. |
I should have mentioned, it appears that the numpydoc way of getting signatures on class method is inconsistent between python 2 and python 3. Maybe another reason to just say, "screw it... use autodoc signatures". But I don't want to upset the apple cart. |
(and who builds docs on python 2 anyway) |
Do tests pass if you always use autodoc? It would be nice to only have one code path if possible, especially if we know that the non-autodoc one is buggy. |
@larsoner I honestly haven't tried that. I'll try to get to it in the next few days... |
@larsoner So it was much easier than I thought... Answer is that if I remove this code, we should revert to auto doc. numpydoc/numpydoc/docscrape.py Lines 575 to 590 in b45eb2b
The only induced failure is this one... numpydoc/numpydoc/tests/test_docscrape.py Lines 723 to 731 in b45eb2b
|
numpydoc/tests/test_docscrape.py
Outdated
pass | ||
|
||
fdoc = FunctionDoc(func=my_func) | ||
assert fdoc['Signature'] == r'my_func(a, b, \*\*kwargs)' |
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.
This might actually be important. Do things with *args, **kwargs
render properly now? That's what this is meant to check/ensure. Can we replace this test rather than just remove it? Maybe check that the RST generated has the *
s escaped properly?
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.
The other thing I wonder about is that git grep Signature
has more hits in numpydoc
than just the ones removed here. is self['Signature']
now created by autodoc
automatically so we don't need to worry about this? Or is self['Signature']
always None after this PR so that logic elsewhere like the following could be simplified?
numpydoc/numpydoc.py: sig = doc['Signature'] or getattr(obj, '__text_signature__', None)
Would you be ok if I made a PR to turn on coveralls codecov? Might be easier to see what's really being tested and where. |
Sure, they're a bit buggy but we can configure then to be useful |
Published statsmodels devel docs using @thequackdaddy 's branch. **kwargs looks fine. |
@thequackdaddy feel free to rebase now that #230 is in and then hopefully you can change the lines marked |
Rebase is done and I think that might be all we need. Thoughts? |
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.
Looks good to me, +1 for merge. Would be good to get another set of eyes on it, though, in case I'm missing something about why we had that code in there in the first place. It is about 10 years old, though, so maybe its just there to work around something that has been fixed nowadays.
Please update the PR title. It certainly looks like a simple solution. I'm building scikit-learn docs with this for review at scikit-learn/scikit-learn#14681 |
@jnothman I changed the title. |
I like how this looks in the member methods listing (autosummary). It also affects the signatures shown in method documentation. Here I see things like |
@seberg -- this PR does fix the issues we were discussing at the dask developers meeting. If this can be merged and a new release cut then we can unpin |
@gforsyth, am I alone in getting those $s rendering, per my comment above (#221 (comment))? I don't know why they are appearing... |
Hey @jnothman -- I |
Easy to check for that as well and replace. |
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.
Just a minor simplification idea, otherwise LGTM
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.
LGTM +1 for merge.
@bashtage or @gforsyth do you want to try it out and/or review? @jnothman you might also be interested in looking again
@thequackdaddy if nobody complains in a few days feel free to ping me again, I'll run some final tests locally and merge
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.
Changes look good and I've confirmed that building docs for dask/dask
works as expected. Thanks for pushing on this!
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.
Thanks
numpydoc/tests/test_numpydoc.py
Outdated
assert (_clean_text_signature('func($self, foo="$self")') | ||
== 'func(foo="$self")') | ||
assert _clean_text_signature('func(self, other)') == 'func(self, other)' | ||
assert _clean_text_signature('func(self, $self)') == 'func(self)' |
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.
I'm not sure this is a thing :)
numpydoc/numpydoc.py
Outdated
sig = sig[end:-1] | ||
params = sig.split(', ') | ||
for param in ('$self', '$module', '$type', '/'): | ||
if param in params: |
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.
I don't think it'll happen often, but I'm still not comfortable with the fact that this processes all parts of the sig. Can't we check explicitly that the /
precedes a *
, and that the $
is at the beginning, rather than use the split and join logic?
sig = re.sub(r'^\$(self|module|type), ', '', sig, count=1)
sig = re.sub(r', /, \*', ', *', sig, count=1)
Is this not sufficient?
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.
I'll confess that I have (almost) no understanding of how these C text signature things work.
What you have would make it so func($self)
would still be func($self)
. Is that alright? I have no idea what the possible syntax is for this.
If you (or someone else) has some kind of documentation on what is possible, that would make this back-and-forth much easier.
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.
Sorry, I meant to apply those substitutions after
start_pattern = re.compile(r"^[^(]*\(")
start, end = start_pattern.search(sig).span()
start_sig = sig[start:end]
sig = sig[end:-1]
They're just a bit more careful than splitting on every comma.
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.
Actually I think this makes sense. Let me change that.
To handle func($self)
, I guess you could just add a ’, ‘
right before your code. Then use regex to strip off a trailing ’, ‘
if it exists.
Do you think that would work?
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.
Sorry, didn't handle that case, did I?
Can use r'^\$(self|module|type)(, |$))?'
which will strip a comma, or check that we're at the end.
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.
Take a peek at this. I had to do something to check whether the /
was the start of the string or preceded by a ,
.
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.
The output looks good for Scikit-learn, and I think this is safer than it was yesterday, so I'm okay with it.
numpydoc/numpydoc.py
Outdated
sig = sig[end:-1] | ||
params = sig.split(', ') | ||
for param in ('$self', '$module', '$type', '/'): | ||
if param in params: |
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.
Sorry, I meant to apply those substitutions after
start_pattern = re.compile(r"^[^(]*\(")
start, end = start_pattern.search(sig).span()
start_sig = sig[start:end]
sig = sig[end:-1]
They're just a bit more careful than splitting on every comma.
So one last thing: I think this now stops displaying I suspect we should at least document this in a change log. |
It looks like this project generally builds changelogs as part of the release cycle, unless I'm missing something? I just see a release notes file that looks like it was built for the 1.0 release. I don't see where I can edit in that? |
Never mind. I guess the file is meant to be cumulative. I'll give it the old college try. |
Is everyone content? |
Thank you @thequackdaddy! |
xref #220
I think this should pass. It fails because method signatures include
self
.I'll be happy to help make this pass.