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

Sphinx not respecting __signature__ #7613

Closed
asmeurer opened this issue May 4, 2020 · 3 comments
Closed

Sphinx not respecting __signature__ #7613

asmeurer opened this issue May 4, 2020 · 3 comments

Comments

@asmeurer
Copy link
Contributor

asmeurer commented May 4, 2020

I am having an issue with Sphinx 3.0.3 where classes that define __signature__ are being shown with *args (the naive signature from __init__). This is the project https://github.com/Quansight/ndindex/tree/master/docs.

See for example https://quansight.github.io/ndindex/api.html#slice. The signature on the class in the docs says "Slice(*args)". But if you call inspect.signature, you get

>>> from ndindex import Slice
>>> import inspect
>>> inspect.signature(Slice)
<Signature (start, stop=<class 'ndindex.slice.default'>, step=None)>

You can see __signature__ defined on the superclass here.

This was supposedly fixed in #2828, so either there was a regression, or else somehow the code doesn't handle what I am doing properly

@tk0miya tk0miya added this to the 3.1.0 milestone May 10, 2020
@tk0miya
Copy link
Member

tk0miya commented May 10, 2020

Note: ndindex provides Slice.__signature__ via classproperty. But autodoc refers Slice.__init__.__signature__ instead. This will not be fixed even if #7384 merged.

https://github.com/Quansight/ndindex/blob/6367b37d4d89094038568e43788208caa1f6de38/ndindex/ndindex.py#L98-L107

@asmeurer
Copy link
Contributor Author

I use a class property so that help() shows the signature on the class, not just on instances. Looking at the __signature__ of the init method itself doesn't seem helpful. Is that even something that can be overridden?

@eric-wieser
Copy link
Contributor

eric-wieser commented May 26, 2020

This ought to be fairly straightforward to add another special-case for.

The problem is that Sphinx cannot use inspect.signature directly, as doing so would skip its hooks that allow it to parse # type: comments. So Sphinx tries to implement its own version of inspect.signature that lines up with the regular implementation in the cases that were worth thinking about.

In this case, that implementation is missing the code path for a __signature__ attribute.

@tk0miya tk0miya modified the milestones: 3.1.0, 3.2.0 Jun 6, 2020
@tk0miya tk0miya modified the milestones: 3.2.0, 3.3.0 Aug 8, 2020
@tk0miya tk0miya modified the milestones: 3.3.0, 3.4.0 Nov 1, 2020
@tk0miya tk0miya closed this as completed in 9a44e45 Nov 4, 2020
tk0miya added a commit that referenced this issue Nov 4, 2020
Fix #7613: autodoc: autodoc does not respect __signature__ of the class
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants