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

Failure to generate function signature #3726

Closed
orenbenkiki opened this issue May 8, 2017 · 8 comments
Closed

Failure to generate function signature #3726

orenbenkiki opened this issue May 8, 2017 · 8 comments

Comments

@orenbenkiki
Copy link

Sphinx (version 1.5.2) fails to generate function signature in case there are typing problems.

Problem

http://stackoverflow.com/questions/37362351/sphinx-does-not-produce-function-signature contains a good description of the problem (which also happens for me). It seems that if the typing module chokes on some code, sphinx will therefore fail to generate any signature for the affected function. In my specific case (Python 3.6, mypy 0.501), the code actually passes mypy (with the occasional # type: ignore comment), but I still get the WARNING: error while formatting arguments for ...: ... object has no attribute ....

Expected results

Sphinx should generate a function signature regardless of spurious failures of the typing module; the solution suggested in http://stackoverflow.com/questions/37362351/sphinx-does-not-produce-function-signature makes sense.

Reproducible project / your project

I haven't isolated the offending code out of my project - if/when I'll upload the project to Github, I'll add a link to it (this may take a while - my company intends to release it, but for now it is an internal project).

Environment info

  • OS: Linux
  • Python version: 3.6
  • Sphinx version: 1.5.2
@tk0miya
Copy link
Member

tk0miya commented May 8, 2017

Thank you for reporting.
LGTM for the patch on SO.

It would be very nice if anybody provides the reproducible example. Then I will patch the code with testcase.

@tk0miya tk0miya modified the milestones: 1.6.1, 1.5.6 May 8, 2017
@tk0miya tk0miya modified the milestones: 1.6.3, 1.6.2 May 23, 2017
@tk0miya tk0miya modified the milestones: 1.6.4, 1.6.3 Jun 24, 2017
@tk0miya
Copy link
Member

tk0miya commented Sep 6, 2017

Any updates? If none, I can't merge this...

@orenbenkiki
Copy link
Author

The solution from stack overflow seems sensible...:

Solution: try-excepting the erroneous code:

So i tried to fix the issue by quick and dirty try-except-clause:

From:

introspected_hints = (typing.get_type_hints(function)
                          if typing and hasattr(function, '__code__')`

to:

try:
   introspected_hints = (typing.get_type_hints(function)
                             if typing and hasattr(function, '__code__')
except AttributeError:
   introspected_hints = {}

Indeed, the quick fix solved both problems: no more Warnings were created and further the
documentation shows the right (!) signature of my functions.

@tk0miya
Copy link
Member

tk0miya commented Sep 24, 2017

No, I'd like to know how to raise the error. I need some example to reproduce the bug before merging it.

@tk0miya tk0miya modified the milestones: 1.6.4, 1.6.5 Sep 24, 2017
@tk0miya
Copy link
Member

tk0miya commented Oct 21, 2017

Any updates? I think this is good fix, so I'd like to merge this. To do that, I need reproducible example.

@tk0miya tk0miya modified the milestones: 1.6.5, 1.6.6 Oct 21, 2017
@tk0miya
Copy link
Member

tk0miya commented Jan 1, 2018

I marked this as "help wanted". Please let me know how to reproduce the problem.

@tk0miya tk0miya removed this from the 1.6.6 milestone Jan 1, 2018
@tk0miya
Copy link
Member

tk0miya commented Aug 17, 2018

Finally I found the reproducible example: #5306!
I made a PR #5309 for this.

@tk0miya tk0miya added this to the 1.7.7 milestone Aug 17, 2018
@tk0miya
Copy link
Member

tk0miya commented Aug 17, 2018

Fixed.
Thank you for reporting.

@tk0miya tk0miya closed this as completed Aug 17, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 12, 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

2 participants