-
Notifications
You must be signed in to change notification settings - Fork 53
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
Function overload support and param/return-sections-undocumented change #595
Conversation
Replaces and closes twisted#417, fixes twisted#406
Hello @cretz, I know the PR is marked as draft so you'll probably work on it again later, but I want to give a little heads-up about little stuff I saw that might be worth mentioning before going to far in the hacking: Since the object Also did you read this ticket about types in signatures ? #473 Thanks for you work on this already :) Talk to you later, |
@tristanlatr - Thanks! Yeah, I have it draft because I was (properly) afraid the CI checks here might not pass. I am fixing and then will open full review.
Ok, I can remove the factory part for that
I am seeing it now. Seems like removing the entire parameters/return section if all are "Undocumented", correct? But otherwise leave as is? Usually I would say this should be a separate PR, but I have also been really wanting this (I have big shortcut methods that are documented as just "see whatever"). I am adding now. |
Codecov ReportBase: 92.31% // Head: 92.39% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #595 +/- ##
==========================================
+ Coverage 92.31% 92.39% +0.08%
==========================================
Files 45 45
Lines 7959 8026 +67
Branches 1736 1750 +14
==========================================
+ Hits 7347 7416 +69
+ Misses 356 355 -1
+ Partials 256 255 -1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
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.
It's going to be a great improvement no to display undocumented EVERYWHERE.
I made a few comments that I believe are worth changing bits of the code. I know I wrote this code at first but it was about a year ago, and we now have a better colorizer for AST values that is worth using.
Also, I can write a couple of test cases for the edge cases if you want.
Thanks for your work,
Talk to you later,
@@ -239,8 +289,8 @@ def f(a, b): | |||
classic_fmt = docstring2html(classic_mod.contents['f']) | |||
assert annotation_fmt == classic_fmt | |||
|
|||
@pytest.mark.xfail |
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 didn't know we had that!
Also, could you include a few entries in the change log to summarize what's been changed in this PR? Thanks. |
Will make updates, probably some time tomorrow |
Updates made, can re-review (assuming CI checks pass, if not, will force-push whatever tiny changes needed) |
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 think there is a little bug
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.
Overhaul looks good, only minor suggestions.
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.
Hello @cretz,
Thanks for your work on this, turns out it's more complicated than expected (and we're missing regression tests). I believe more reasoning is needed to honour @type:
fields that don't have associated documentation.
Talk to you later,
pydoctor/epydoc2stan.py
Outdated
# Only include parameter or return sections if any are documented | ||
if any(p.body for p in self.parameter_descs): |
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.
There is something that bothers me, here. (see other comment).
We need a way to determine of the type info is coming from AST, in which case we should display it only if it's documented or if the type is coming from docstring fields, in which case it should display anyhow (with undocumented notes). In terms of implementation, the resolve_types()
might need an adjustment in order to track if the FieldDesc
is create from resolve_types()
(meaning we only have AST info), for instance by creating _BaseFieldDesc
superclass of FieldDesc
and AstFieldDesc
and use that instead from resolve_types()
. Then check for the existence of FieldDesc
instances in self.parameter_descs
.
Tell me if you think it could work,
Talk to you later,
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 now work since we want to track the origin of the type info, and this would only work to track undocumented 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 believe adding a simple attribute FieldDesc.type_origin: Enum value - AST/DOCSTRING
could make the trick.
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.
We need a way to determine of the type info is coming from AST, in which case we should display it only if it's documented or if the type is coming from docstring fields, in which case it should display anyhow (with undocumented notes).
This seems a bit off. If someone has chosen to use @type
(maybe to help their IDE or whatever) but have chosen not to use @param
, they are choosing to not document, right?
It seems you are suggested that @type
be treated as an empty @param
doc? How would I, as a user that doesn't use @type
, be able to get that empty documentation functionality the way those that do use @type
get?
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.
It seems you are suggested that @type be treated as an empty @param doc?
Otherwise we would just ignore it. Because free text can't be included in signatures, and should not.
How would I, as a user that doesn't use @type, be able to get that empty documentation functionality the way those that do use @type get?
You are raising valid points here.
The simplest thing we could do when a @type
field is alone with no documentation (either coming from @param
or @var
, @ivar
or @cvar
) it to report a warning saying that info is ignored if it's not alongside actual documentation.
But still, it doesn't feels the best to me; because we include them right now, and would ignore them in the next version, this would be a breaking change. Also, I believe we can only include the type with numpy-style docstring, resulting into @type
field being created with empty @param
field:
>>> from pydoctor.napoleon.docstring import NumpyDocstring
>>> d = NumpyDocstring('''
... Args
... ----
... a:str
... b:int
... ''')
>>> str(d)
'\n:param a:\n:type a: str\n:param b:\n:type b: int
What I'm saying is that:
Args
-----
a:str
b:int
Should be treated the same manner as
@type a:str
@type b:int
What do you think?
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.
because we include them right now, and would ignore them in the next version, this would be a breaking change
This to me is enough to justify it. So to confirm - Include docs if @type
or @param
present, otherwise no docs if neither present (regardless if type hinting). Sound right? I can definitely add the type origin on the desc there.
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.
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've addressed this issue.
Will look/respond/fix probably early next week. |
I apologize I have not been able to get back on this. I have been swamped with other tasks. I will try to return soon. |
Hi @cretz, Do you think you will have time to finalize the work on this PR? And if you don't have time in the end, I'll probably try to make it work anyway, because I believe this adjustments worth it. But no rush anyhow, Tell me what you think, |
@tristanlatr - Sorry, I have been caught up getting our Python SDK going and have not been able to prioritize docs. I will try to revisit in a few days. Update: Still hoping to revisit this soon time permitting. |
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.
@tristanlatr - I am now back available. Sorry for the hiatus. I have added response on the primary point about treating the two ways of annotating types differently. Once we land on a solution there, I'll fix conflicts and apply other needed changes.
pydoctor/epydoc2stan.py
Outdated
# Only include parameter or return sections if any are documented | ||
if any(p.body for p in self.parameter_descs): |
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.
We need a way to determine of the type info is coming from AST, in which case we should display it only if it's documented or if the type is coming from docstring fields, in which case it should display anyhow (with undocumented notes).
This seems a bit off. If someone has chosen to use @type
(maybe to help their IDE or whatever) but have chosen not to use @param
, they are choosing to not document, right?
It seems you are suggested that @type
be treated as an empty @param
doc? How would I, as a user that doesn't use @type
, be able to get that empty documentation functionality the way those that do use @type
get?
Hi @cretz, Do you think you’ll be able to work on this changes again ? |
@tristanlatr - Sorry, this keeps getting pushed down on my priority list :-) It is still definitely on my TODO (this powers https://python.temporal.io/ for us), but cannot promise exact time. |
…oming from the docstrings.
@tristanlatr - Thanks for helping this move forward! (pardon my absence) |
… inconsistencies with the literal css class.
Ok, we're getting there. This is ready :) |
pydoctor/epydoc2stan.py
Outdated
# Only include parameter or return sections if any are documented | ||
if any(p.body for p in self.parameter_descs): |
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've addressed this issue.
Any trepidation about this change in twisted docs ? @glyph |
We don't use a lot of overloads yet, and as I understand it, despite the docs being arguably slightly "uglier" with this change, the ugliness is a reflection of real-world complexity that is currently just missing. So I would regard this as an improvement. I think that having an option to toggle wrapping, specifically Black-compatible wrapping, would be good to have, but that is an unrelated problem for function signatures, so I don't think it has any bearing on this PR. |
Thanks for your feedback. I'll merge this PR :) Any option for line wrapping / disabling annotation in function signatures can be added later. |
Handle
@overload
decorator and situation where all params/returns are undocumented. Specifically:@overload
functions and add@overload
decorator above themExample, for reST-format of:
Result:
Note how
(source)
is below the signatures instead of to the right as it would be w/ just one signature. Seems to be an acceptable tradeoff for now.For undocumented reST-format of:
Result:
Notice the lack of parameter and return sections.
Here's an example of a really large overload from some source in my company's repo:
Yes it can appear kind of like a large mess, but there aren't really good alternatives and it's my company's fault for using so many args. I don't think we'd want to wrap param signatures nor do I think we'd want to do a diff and only have the overloads show what's unique to them.