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

building psf/requests documentation fails with AttributeError: 'LookupDict' object has no attribute '__name__' #8616

Closed
eriol opened this issue Dec 29, 2020 · 5 comments

Comments

@eriol
Copy link

eriol commented Dec 29, 2020

Describe the bug

Since sphinx 3.4.1 building psf/requests documentation fails with the following:

sphinx-build -b html -d _build/doctrees   . _build/html
Running Sphinx v3.4.1
loading intersphinx inventory from https://docs.python.org/3/objects.inv...
loading intersphinx inventory from https://urllib3.readthedocs.io/en/latest/objects.inv...
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 15 source files that are out of date
updating environment: [new config] 15 added, 0 changed, 0 removed
reading sources... [  6%] api                                                                                                                                                                
Exception occurred:
  File "/usr/lib/python3/dist-packages/sphinx/util/typing.py", line 160, in _restify_py37
    return ':obj:`%s.%s`' % (cls.__module__, cls.__name__)
AttributeError: 'LookupDict' object has no attribute '__name__'
The full traceback has been saved in /tmp/sphinx-err-yt45bplo.log, if you want to report the issue to the developers.

Attached the full log: sphinx-err-yt45bplo.log

The issue is not reproducible using sphinx 3.3.1.

To Reproduce
In addiction to build requests' documentation I managed to reproduce the issue in the interactive python console using the following:

Python 3.9.1 (default, Dec  8 2020, 07:51:42) 
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> import sphinx
>>> requests.__version__
'2.25.0'
>>> sphinx.__version__
'3.4.1'
>>> from requests import codes
>>> from sphinx.util.typing import restify
>>> restify(codes)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/sphinx/util/typing.py", line 103, in restify
    return _restify_py37(cls)
  File "/usr/lib/python3/dist-packages/sphinx/util/typing.py", line 160, in _restify_py37
    return ':obj:`%s.%s`' % (cls.__module__, cls.__name__)
AttributeError: 'LookupDict' object has no attribute '__name__'

I'm able to reproduce the issue in a clean virtualenv with only requests and sphinx installed.

Thanks!

@eriol eriol added the type:bug label Dec 29, 2020
@ConstantinoSchillebeeckx

I'm seeing the same building docs with Airflow

File "/somewhere/lib/python3.7/site-packages/sphinx/util/typing.py", line 158, in _restify_py37
    return ':obj:`%s.%s`' % (cls.__module__, cls.__name__)
AttributeError: 'PythonOperator' object has no attribute '__name__'

Downgrading to 3.3.1 avoids the issue.

@tk0miya
Copy link
Member

tk0miya commented Dec 30, 2020

It seems requests' document is using autoclass for requests.codes.
https://github.com/psf/requests/blob/4f6c0187150af09d085c03096504934eb91c7a9e/docs/api.rst

But it is not a class. Is this mark-up intended?
https://github.com/psf/requests/blob/4f6c0187150af09d085c03096504934eb91c7a9e/requests/status_codes.py#L105

I don't know autoclass directive should support non-class items. But it is not intended to make a breaking change. So I'll try to fix it if possible.

@tk0miya tk0miya added this to the 3.4.2 milestone Dec 30, 2020
@tk0miya
Copy link
Member

tk0miya commented Dec 30, 2020

@ConstantinoSchillebeeckx Is your case the same as requests' case? Please check your document. If not, please file another issue to investigate your case in detail.

tk0miya added a commit to tk0miya/sphinx that referenced this issue Dec 30, 2020
… to autoclass

Since 3.4.0, AttributeError is raised when non-class object is passed to
the autoclass directive.  It has built successfully before 3.4.0
release.  So this handles the exception on generating "alias" text.
tk0miya added a commit that referenced this issue Dec 31, 2020
Fix #8616: autodoc: AttributeError when non-class is passed to autoclass
@tk0miya tk0miya closed this as completed Dec 31, 2020
@eriol
Copy link
Author

eriol commented Dec 31, 2020

@tk0miya many thanks for the analysis and the fix! That line was not touched in 5 years, so I think that since just worked it was used and never touched again.

@tk0miya
Copy link
Member

tk0miya commented Jan 1, 2021

@eriol :-) I recommend you to use autodata directive for variables instead of autoclass. At present, Sphinx renders it as an attribute. But the behavior might be changed because the author considers it is a "class".

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