-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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: fix constructor signatures for classes derived from typing.Generic #8142
Conversation
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.
@@ -290,6 +290,35 @@ def foo3(self, d='\n'): | |||
'(b, c=42, *d, **e)' | |||
|
|||
|
|||
@pytest.mark.skipif(sys.version_info < (3, 5), reason='typing is available since python3.5.') | |||
def test_autodoc_process_signature_typing_generic(app): |
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.
Could you rewrite testcase using do_autodoc()
?
- Add a target class to
tests/roots/test-ext-autodoc/targets/
- Call
do_autodoc()
. There are many examples in this file.
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.
Done. I added a new file because I did not feel it fit in any of the existing test files.
This test is currently failing because typing.Generic.__new__ clobbers the real signature.
When documenting classes derived from typing.Generic (essentially all classes in the typing module) the constructor signature would show an unhelpful (*args, **kwds). typing.Generic has a __new__ method which was picked up by sphinx. With this patch it is skipped and constructor signatures for generic classes are shown as they should.
eddb6c3
to
740be7f
Compare
Merged. Thank you for your support! |
Subject: take the constructor signature from init instead of new for classes derived from typing.Generic
Feature or Bugfix
Purpose
When documenting classes derived from
typing.Generic
(essentially all classes in the typing module) the constructor signature would show an unhelpful(*args, **kwds).
typing.Generic.__new__
was being picked up by sphinx.ext.autodoc. With this patch it is skipped and constructor signatures for generic classes are taken from__init__
.Detail
I copied the code that was used to skip callable metaclasses.