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 is unable to find type hints for a functools.partial #5498

Closed
elyezer opened this issue Sep 27, 2018 · 3 comments
Closed

Sphinx is unable to find type hints for a functools.partial #5498

elyezer opened this issue Sep 27, 2018 · 3 comments
Labels
Milestone

Comments

@elyezer
Copy link

elyezer commented Sep 27, 2018

Subject: Sphinx is unable to find type hints for a functools.partial

Problem

  • Running using the nitpick mode makes sphinx build to fail when trying to find type hints for a functools.partial object.

Procedure to reproduce the problem

$ make html

Running Sphinx v1.8.1
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 67 source files that are out of date
updating environment: 67 added, 0 changed, 0 removed
reading sources... [100%] index                                                                                    

Warning, treated as error:
Invalid type annotation found on functools.partial(<function cli_command at 0x7f280cc96e18>, 'qpc source show'). Ignored: TypeError("functools.partial(<function cli_command at 0x7f280cc96e18>, 'qpc source show') is not a module, class, method, or function.",)
make: *** [Makefile:24: html] Error 2

Error logs / results

Invalid type annotation found on functools.partial(<function cli_command at 0x7f280cc96e18>, 'qpc source show'). Ignored: TypeError("functools.partial(<function cli_command at 0x7f280cc96e18>, 'qpc source show') is not a module, class, method, or function.",)

Expected results

Sphinx should not raise an warning if it can't find a functools.partial or provide an option to ignore such warnings when running on the nitpick mode.

This warning was not raised when running Sphinx 1.7.9

Reproducible project / your project

Environment info

  • OS: Fedora 28
  • Python version: 3.6.6
  • Sphinx version: 1.8.1
@tk0miya tk0miya added this to the 1.8.2 milestone Sep 29, 2018
@tk0miya
Copy link
Member

tk0miya commented Oct 14, 2018

Note: py3 does not support typing.get_type_hints(partial_func):

$ cat test.py
import sys
from functools import partial
from typing import get_type_hints

print('Python version: %s\n' % (sys.version_info,))
def foo(): pass
print(get_type_hints(partial(foo)))
$ python2.7 test.py
Python version: sys.version_info(major=2, minor=7, micro=15, releaselevel='final', serial=0)

None
$ python3.5 test.py
Python version: sys.version_info(major=3, minor=5, micro=6, releaselevel='final', serial=0)

Traceback (most recent call last):
  File "test.py", line 7, in <module>
    print(get_type_hints(partial(foo)))
  File "/Users/tkomiya/.pyenv/versions/3.5.6/lib/python3.5/typing.py", line 1544, in get_type_hints
    'or function.'.format(obj))
TypeError: functools.partial(<function foo at 0x10f7278c8>) is not a module, class, method, or function.
$ python3.6 test.py
Python version: sys.version_info(major=3, minor=6, micro=5, releaselevel='final', serial=0)

Traceback (most recent call last):
  File "test.py", line 7, in <module>
    print(get_type_hints(partial(foo)))
  File "/Users/tkomiya/.pyenv/versions/3.6.5/lib/python3.6/typing.py", line 1527, in get_type_hints
    'or function.'.format(obj))
TypeError: functools.partial(<function foo at 0x106136e18>) is not a module, class, method, or function.
$ python3.7 test.py
Python version: sys.version_info(major=3, minor=7, micro=0, releaselevel='final', serial=0)

Traceback (most recent call last):
  File "test.py", line 7, in <module>
    print(get_type_hints(partial(foo)))
  File "/Users/tkomiya/.pyenv/versions/3.7.0/lib/python3.7/typing.py", line 993, in get_type_hints
    'or function.'.format(obj))
TypeError: functools.partial(<function foo at 0x10a0a71e0>) is not a module, class, method, or function.

tk0miya added a commit to tk0miya/sphinx that referenced this issue Oct 14, 2018
tk0miya added a commit to tk0miya/sphinx that referenced this issue Oct 14, 2018
tk0miya added a commit that referenced this issue Oct 15, 2018
Fix #5498: autodoc: unable to find type hints for a ``functools.partial``
@tk0miya
Copy link
Member

tk0miya commented Oct 15, 2018

Fixed by #5531 .
Thank you for reporting.

@tk0miya tk0miya closed this as completed Oct 15, 2018
@elyezer
Copy link
Author

elyezer commented Oct 15, 2018

Thank you @tk0miya very much for fixing this. I will give it a try later.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants