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

4.0.2: sphinx fails on generate documenrtation of requests module #9404

Closed
kloczek opened this issue Jul 4, 2021 · 3 comments
Closed

4.0.2: sphinx fails on generate documenrtation of requests module #9404

kloczek opened this issue Jul 4, 2021 · 3 comments

Comments

@kloczek
Copy link

kloczek commented Jul 4, 2021

Describe the bug
Sphinx fails generate requests module documentation.

To Reproduce

git clone https://github.com/requests/requests/
cd requests
python3 setup.py build
python3 setup.py build_sphinx -b man --build-dir build/sphinx

Expected behavior

Your project

Screenshots

+ /usr/bin/python3 setup.py build_sphinx -b man --build-dir build/sphinx
running build_sphinx
Running Sphinx v4.0.2
making output directory... done
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 [man]: all manpages
updating environment: [new config] 15 added, 0 changed, 0 removed
reading sources... [  6%] api
Exception occurred:
  File "/usr/lib/python3.8/site-packages/sphinx/util/typing.py", line 112, in restify
    elif cls in INVALID_BUILTIN_CLASSES:
TypeError: unhashable type: 'LookupDict'
The full traceback has been saved in /tmp/sphinx-err-0z5530lc.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!
[tkloczko@barrel SPECS]$ cat /tmp/sphinx-err-0z5530lc.log
# Sphinx version: 4.0.2
# Python version: 3.8.11 (CPython)
# Docutils version: 0.16 release
# Jinja2 version: 3.0.1
# Last messages:
#   making output directory...
#   done
#   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 [man]: all manpages
#   updating environment:
#   [new config]
#   15 added, 0 changed, 0 removed
#   reading sources... [  6%] api
# Loaded extensions:
#   sphinx.ext.mathjax (4.0.2) from /usr/lib/python3.8/site-packages/sphinx/ext/mathjax.py
#   sphinxcontrib.applehelp (1.0.1) from /usr/lib/python3.8/site-packages/sphinxcontrib/applehelp/__init__.py
#   sphinxcontrib.devhelp (1.0.1) from /usr/lib/python3.8/site-packages/sphinxcontrib/devhelp/__init__.py
#   sphinxcontrib.htmlhelp (1.0.1) from /usr/lib/python3.8/site-packages/sphinxcontrib/htmlhelp/__init__.py
#   sphinxcontrib.serializinghtml (1.1.5) from /usr/lib/python3.8/site-packages/sphinxcontrib/serializinghtml/__init__.py
#   sphinxcontrib.qthelp (1.0.2) from /usr/lib/python3.8/site-packages/sphinxcontrib/qthelp/__init__.py
#   alabaster (0.7.12) from /usr/lib/python3.8/site-packages/alabaster/__init__.py
#   sphinx.ext.autodoc.preserve_defaults (1.0) from /usr/lib/python3.8/site-packages/sphinx/ext/autodoc/preserve_defaults.py
#   sphinx.ext.autodoc.type_comment (4.0.2) from /usr/lib/python3.8/site-packages/sphinx/ext/autodoc/type_comment.py
#   sphinx.ext.autodoc (4.0.2) from /usr/lib/python3.8/site-packages/sphinx/ext/autodoc/__init__.py
#   sphinx.ext.intersphinx (4.0.2) from /usr/lib/python3.8/site-packages/sphinx/ext/intersphinx.py
#   sphinx.ext.todo (4.0.2) from /usr/lib/python3.8/site-packages/sphinx/ext/todo.py
#   sphinx.ext.viewcode (4.0.2) from /usr/lib/python3.8/site-packages/sphinx/ext/viewcode.py
Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/sphinx/setup_command.py", line 175, in run
    app.build(force_all=self.all_files)
  File "/usr/lib/python3.8/site-packages/sphinx/application.py", line 350, in build
    self.builder.build_update()
  File "/usr/lib/python3.8/site-packages/sphinx/builders/__init__.py", line 289, in build_update
    self.build(['__all__'], to_build)
  File "/usr/lib/python3.8/site-packages/sphinx/builders/__init__.py", line 306, in build
    updated_docnames = set(self.read())
  File "/usr/lib/python3.8/site-packages/sphinx/builders/__init__.py", line 413, in read
    self._read_serial(docnames)
  File "/usr/lib/python3.8/site-packages/sphinx/builders/__init__.py", line 434, in _read_serial
    self.read_doc(docname)
  File "/usr/lib/python3.8/site-packages/sphinx/builders/__init__.py", line 474, in read_doc
    doctree = read_doc(self.app, self.env, self.env.doc2path(docname))
  File "/usr/lib/python3.8/site-packages/sphinx/io.py", line 188, in read_doc
    pub.publish()
  File "/usr/lib/python3.8/site-packages/docutils/core.py", line 217, in publish
    self.document = self.reader.read(self.source, self.parser,
  File "/usr/lib/python3.8/site-packages/sphinx/io.py", line 108, in read
    self.parse()
  File "/usr/lib/python3.8/site-packages/docutils/readers/__init__.py", line 77, in parse
    self.parser.parse(self.input, document)
  File "/usr/lib/python3.8/site-packages/sphinx/parsers.py", line 100, in parse
    self.statemachine.run(inputlines, document, inliner=self.inliner)
  File "/usr/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 170, in run
    results = StateMachineWS.run(self, input_lines, input_offset,
  File "/usr/lib/python3.8/site-packages/docutils/statemachine.py", line 241, in run
    context, next_state, result = self.check_line(
  File "/usr/lib/python3.8/site-packages/docutils/statemachine.py", line 459, in check_line
    return method(match, context, next_state)
  File "/usr/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 2769, in underline
    self.section(title, source, style, lineno - 1, messages)
  File "/usr/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 327, in section
    self.new_subsection(title, lineno, messages)
  File "/usr/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 393, in new_subsection
    newabsoffset = self.nested_parse(
  File "/usr/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 281, in nested_parse
    state_machine.run(block, input_offset, memo=self.memo,
  File "/usr/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 196, in run
    results = StateMachineWS.run(self, input_lines, input_offset)
  File "/usr/lib/python3.8/site-packages/docutils/statemachine.py", line 241, in run
    context, next_state, result = self.check_line(
  File "/usr/lib/python3.8/site-packages/docutils/statemachine.py", line 459, in check_line
    return method(match, context, next_state)
  File "/usr/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 2769, in underline
    self.section(title, source, style, lineno - 1, messages)
  File "/usr/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 327, in section
    self.new_subsection(title, lineno, messages)
  File "/usr/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 393, in new_subsection
    newabsoffset = self.nested_parse(
  File "/usr/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 281, in nested_parse
    state_machine.run(block, input_offset, memo=self.memo,
  File "/usr/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 196, in run
    results = StateMachineWS.run(self, input_lines, input_offset)
  File "/usr/lib/python3.8/site-packages/docutils/statemachine.py", line 241, in run
    context, next_state, result = self.check_line(
  File "/usr/lib/python3.8/site-packages/docutils/statemachine.py", line 459, in check_line
    return method(match, context, next_state)
  File "/usr/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 2342, in explicit_markup
    nodelist, blank_finish = self.explicit_construct(match)
  File "/usr/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 2354, in explicit_construct
    return method(self, expmatch)
  File "/usr/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 2096, in directive
    return self.run_directive(
  File "/usr/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 2146, in run_directive
    result = directive_instance.run()
  File "/usr/lib/python3.8/site-packages/sphinx/ext/autodoc/directive.py", line 162, in run
    documenter.generate(more_content=self.content)
  File "/usr/lib/python3.8/site-packages/sphinx/ext/autodoc/__init__.py", line 1715, in generate
    return super().generate(more_content=more_content,
  File "/usr/lib/python3.8/site-packages/sphinx/ext/autodoc/__init__.py", line 961, in generate
    self.add_content(more_content)
  File "/usr/lib/python3.8/site-packages/sphinx/ext/autodoc/__init__.py", line 1697, in add_content
    more_content = StringList([_('alias of %s') % restify(self.object)], source='')
  File "/usr/lib/python3.8/site-packages/sphinx/util/typing.py", line 112, in restify
    elif cls in INVALID_BUILTIN_CLASSES:
TypeError: unhashable type: 'LookupDict'

Environment info

  • OS: Linux/x86_64
  • Python version: 3.8.11
  • Sphinx version: 4.0.2
  • Sphinx extensions: In copy.py I see::
extensions = [
    "sphinx.ext.autodoc",
    "sphinx.ext.intersphinx",
    "sphinx.ext.todo",
    "sphinx.ext.viewcode",
]
  • Extra tools: [e.g. Browser, tex or something else]
    N/A
    Additional context
    N/A
  • [e.g. URL or Ticket]
    N/A
@astrojuanlu
Copy link
Contributor

For the record, requests uses Sphinx 1.8.5, but this looks like a legitimate Sphinx bug.

The code in question is this:

https://github.com/psf/requests/blob/c45a4dfe6bfc6017d4ea7e9f051d6cc30972b310/requests/structures.py#L89-L105

@tk0miya
Copy link
Member

tk0miya commented Jul 6, 2021

I reproduced the error with this snippet:

.. autoclass:: requests.codes

https://github.com/psf/requests/blob/master/docs/api.rst

It seems requests.codes is not a class. So I don't know why you use autoclass to this. But the error is not expected. So I'll fix this.
https://github.com/psf/requests/blob/c45a4dfe6bfc6017d4ea7e9f051d6cc30972b310/requests/status_codes.py#L105

@tk0miya tk0miya added this to the 4.1.0 milestone Jul 6, 2021
tk0miya added a commit to tk0miya/sphinx that referenced this issue Jul 6, 2021
…e object

The autoclass directive raises TypeError when dict-like object (not a
class) is given as a subject.
tk0miya added a commit that referenced this issue Jul 10, 2021
Fix #9404: autodoc: autoclass raises TypeError for dict-like object
@tk0miya
Copy link
Member

tk0miya commented Jul 10, 2021

Now I merged #9411 into the 4.x branch. So v4.1.0 will not be crashed. But I think requests.codes is not a class. So I recommend you to use autodata directive instead of autoclass.

@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.
Projects
None yet
Development

No branches or pull requests

3 participants