Skip to content
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

Merged
merged 2 commits into from Oct 2, 2020

Conversation

jcarrano
Copy link
Contributor

Subject: take the constructor signature from init instead of new for classes derived from typing.Generic

Feature or Bugfix

  • 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.

Copy link
Member

@tk0miya tk0miya left a 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):
Copy link
Member

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.

Copy link
Contributor Author

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.

@tk0miya tk0miya added this to the 3.3.0 milestone Aug 21, 2020
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.
@tk0miya tk0miya merged commit ec06f55 into sphinx-doc:3.x Oct 2, 2020
@tk0miya
Copy link
Member

tk0miya commented Oct 2, 2020

Merged. Thank you for your support!

tk0miya added a commit that referenced this pull request Oct 2, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants