-
Notifications
You must be signed in to change notification settings - Fork 2k
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
autodoc: Respect type annotations in __new__
, metacls.__call__
, and builtin types
#7384
Conversation
cc3d7cd
to
4a6b701
Compare
__new__
, metacls.__call__
, and builtin types
Failures are all of the form
I think this change is correct - with it, these two classes are now documented identically:
Whereas previously the former would have The two classes give exactly the same result from |
b73b2c1
to
92f6567
Compare
fa12fb0
to
b64a955
Compare
__new__
, metacls.__call__
, and builtin types__new__
, metacls.__call__
, and builtin types
Should we also modify |
We could, but I don't think that matters so much, and would prefer not to do it in this PR. |
b64a955
to
24cefc2
Compare
Comments addressed I 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.
Sorry for late. Let's go forward 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.
LGTM
Needs a rebase to pass tests it seems |
529ef19
to
50c3f3e
Compare
50c3f3e
to
779acfe
Compare
Rebased, hopefully CI will give me some hints this time. |
779acfe
to
9adc963
Compare
6e67041
to
f3a9203
Compare
CI looks like it will pass now. |
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 with nits.
sphinx/ext/autodoc/__init__.py
Outdated
pass | ||
|
||
# retry without arguments for old documenters | ||
args = self.format_args() |
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 format_args()
is called twice.
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 take it back, you're correct. Updated in my latest push.
sphinx/ext/autodoc/__init__.py
Outdated
try: | ||
args = self.format_args(**kwargs) | ||
except TypeError: | ||
# retry without arguments for old documenters | ||
args = self.format_args() | ||
if kwargs: | ||
try: | ||
args = self.format_args(**kwargs) | ||
except TypeError: | ||
# avoid chaining tracebacks, by putting nothing here | ||
pass | ||
|
||
# retry without arguments for old documenters | ||
args = self.format_args() |
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 was called twice before too - this way, we at least:
- Do not call it twice with identical arguments
- Do not chain the exception of the first call with the exception of the second
Does anything actually pass non-empty 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.
It was called twice before too
It's an unexpected result. The TypeError
handler is added only for old Documener classes which does not accept keyword arguments. It implicitly expects format_args()
method does not raise TypeError
.
In this case, I think no reason to raise TypeError
on format_args()
. It should be handled inside it.
Does anything actually pass non-empty kwargs?
Yes. The autosummary extension gives keyword argument.
sphinx/sphinx/ext/autosummary/__init__.py
Line 345 in 62711bc
sig = documenter.format_signature(show_annotation=False) |
Note: It's after 2 AM in Japan. So this is my last comment today. Good night!
790e6da
to
b881a28
Compare
@tk0miya: Think you'll have time to look at this again before 3.1.0? |
b881a28
to
0c33bb3
Compare
This fixes: * Signatures defined by __new__ * Signatures defined by metaclasses * Signatures defined by builtin base classes All of these changes bring the sphinx docs inline with the behavior of `inspect.signature`. Note that this changes autodoc to output `.. py:class: MyClass()` with parentheses even if no user-defined __init__ is present. This is quite deliberate, as if no user-defined `__init__` is present the default is `object.__init__`, which indeed does not take arguments.
0c33bb3
to
4c0e0af
Compare
Of course, Yes. But my request is not changed. Please catch a |
Would you mind adding a comment on the relevant lines? I've moved things around a bit now. |
4c0e0af
to
d558417
Compare
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! Thank you for your patience and cooperation!
Yes, I can improve #7716 now. I'm waiting for merging this :-) |
Feature or Bugfix
Purpose
None of the following work correctly before this patch
__new__
Patch includes a test showing that these now all work.
It's possible other tests will have been affected, will update if needed.
Ping @tk0miya, since you recently looked at annotation stuff.