Skip to content

sphinx.ext.autodoc.typehints: AttributeError: 'Config' object has no attribute '_annotation_globals' #13954

@spaceone

Description

@spaceone

Describe the bug

To report this error to the developers, please open an issue at https://github.com/sphinx-doc/sphinx/issues/. Thanks!
Please also report this if it was a user error, so that a better error message can be provided next time.

I assume it's a user error, but I will report this according to above message.
Feel free to just close the issue.

Traceback
=========
    Traceback (most recent call last):
      File "/usr/local/lib/python3.11/dist-packages/sphinx/events.py", line 404, in emit
        results.append(listener.handler(self.app, *args))
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.11/dist-packages/sphinx_autodoc_typehints/__init__.py", line 745, in process_docstring
        delattr(app.config, "_annotation_globals")
    AttributeError: 'Config' object has no attribute '_annotation_globals'
    
    The above exception was the direct cause of the following exception:
    
    Traceback (most recent call last):
      File "/usr/local/lib/python3.11/dist-packages/sphinx/cmd/build.py", line 432, in build_main
        app.build(args.force_all, args.filenames)
      File "/usr/local/lib/python3.11/dist-packages/sphinx/application.py", line 426, in build
        self.builder.build_update()
      File "/usr/local/lib/python3.11/dist-packages/sphinx/builders/__init__.py", line 375, in build_update
        self.build(
      File "/usr/local/lib/python3.11/dist-packages/sphinx/builders/__init__.py", line 403, in build
        updated_docnames = set(self.read())
                               ^^^^^^^^^^^
      File "/usr/local/lib/python3.11/dist-packages/sphinx/builders/__init__.py", line 519, in read
        self._read_serial(docnames)
      File "/usr/local/lib/python3.11/dist-packages/sphinx/builders/__init__.py", line 584, in _read_serial
        self.read_doc(docname)
      File "/usr/local/lib/python3.11/dist-packages/sphinx/builders/__init__.py", line 648, in read_doc
        publisher.publish()
      File "/usr/local/lib/python3.11/dist-packages/docutils/core.py", line 234, in publish
        self.document = self.reader.read(self.source, self.parser,
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.11/dist-packages/sphinx/io.py", line 103, in read
        self.parse()
      File "/usr/local/lib/python3.11/dist-packages/docutils/readers/__init__.py", line 76, in parse
        self.parser.parse(self.input, document)
      File "/usr/local/lib/python3.11/dist-packages/sphinx/parsers.py", line 86, in parse
        self.statemachine.run(inputlines, document, inliner=self.inliner)
      File "/usr/local/lib/python3.11/dist-packages/docutils/parsers/rst/states.py", line 169, in run
        results = StateMachineWS.run(self, input_lines, input_offset,
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.11/dist-packages/docutils/statemachine.py", line 233, in run
        context, next_state, result = self.check_line(
                                      ^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.11/dist-packages/docutils/statemachine.py", line 445, in check_line
        return method(match, context, next_state)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.11/dist-packages/docutils/parsers/rst/states.py", line 3034, in text
        self.section(title.lstrip(), source, style, lineno + 1, messages)
      File "/usr/local/lib/python3.11/dist-packages/docutils/parsers/rst/states.py", line 325, in section
        self.new_subsection(title, lineno, messages)
      File "/usr/local/lib/python3.11/dist-packages/docutils/parsers/rst/states.py", line 391, in new_subsection
        newabsoffset = self.nested_parse(
                       ^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.11/dist-packages/docutils/parsers/rst/states.py", line 279, in nested_parse
        state_machine.run(block, input_offset, memo=self.memo,
      File "/usr/local/lib/python3.11/dist-packages/docutils/parsers/rst/states.py", line 195, in run
        results = StateMachineWS.run(self, input_lines, input_offset)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.11/dist-packages/docutils/statemachine.py", line 233, in run
        context, next_state, result = self.check_line(
                                      ^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.11/dist-packages/docutils/statemachine.py", line 445, in check_line
        return method(match, context, next_state)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.11/dist-packages/docutils/parsers/rst/states.py", line 2359, in explicit_markup
        self.explicit_list(blank_finish)
      File "/usr/local/lib/python3.11/dist-packages/docutils/parsers/rst/states.py", line 2384, in explicit_list
        newline_offset, blank_finish = self.nested_list_parse(
                                       ^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.11/dist-packages/docutils/parsers/rst/states.py", line 316, in nested_list_parse
        state_machine.run(block, input_offset, memo=self.memo,
      File "/usr/local/lib/python3.11/dist-packages/docutils/parsers/rst/states.py", line 195, in run
        results = StateMachineWS.run(self, input_lines, input_offset)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.11/dist-packages/docutils/statemachine.py", line 233, in run
        context, next_state, result = self.check_line(
                                      ^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.11/dist-packages/docutils/statemachine.py", line 445, in check_line
        return method(match, context, next_state)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.11/dist-packages/docutils/parsers/rst/states.py", line 2662, in explicit_markup
        nodelist, blank_finish = self.explicit_construct(match)
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.11/dist-packages/docutils/parsers/rst/states.py", line 2369, in explicit_construct
        return method(self, expmatch)
               ^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.11/dist-packages/docutils/parsers/rst/states.py", line 2106, in directive
        return self.run_directive(
               ^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.11/dist-packages/docutils/parsers/rst/states.py", line 2156, in run_directive
        result = directive_instance.run()
                 ^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.11/dist-packages/sphinx/ext/autodoc/directive.py", line 175, in run
        documenter.generate(more_content=self.content)
      File "/usr/local/lib/python3.11/dist-packages/sphinx/ext/autodoc/__init__.py", line 1034, in generate
        self._generate(more_content, real_modname, check_module, all_members)
      File "/usr/local/lib/python3.11/dist-packages/sphinx/ext/autodoc/__init__.py", line 1121, in _generate
        self.document_members(all_members)
      File "/usr/local/lib/python3.11/dist-packages/sphinx/ext/autodoc/__init__.py", line 968, in document_members
        documenter._generate(
      File "/usr/local/lib/python3.11/dist-packages/sphinx/ext/autodoc/__init__.py", line 1121, in _generate
        self.document_members(all_members)
      File "/usr/local/lib/python3.11/dist-packages/sphinx/ext/autodoc/__init__.py", line 2119, in document_members
        super().document_members(all_members)
      File "/usr/local/lib/python3.11/dist-packages/sphinx/ext/autodoc/__init__.py", line 968, in document_members
        documenter._generate(
      File "/usr/local/lib/python3.11/dist-packages/sphinx/ext/autodoc/__init__.py", line 1118, in _generate
        self.add_content(more_content)
      File "/usr/local/lib/python3.11/dist-packages/sphinx/ext/autodoc/__init__.py", line 710, in add_content
        for i, line in enumerate(self.process_doc(docstrings)):
      File "/usr/local/lib/python3.11/dist-packages/sphinx/ext/autodoc/__init__.py", line 649, in process_doc
        self._events.emit(
      File "/usr/local/lib/python3.11/dist-packages/sphinx/events.py", line 415, in emit
        raise ExtensionError(
    sphinx.errors.ExtensionError: Handler <function process_docstring at 0x7f953725ef20> for event 'autodoc-process-docstring' threw an exception (exception: 'Config' object has no attribute '_annotation_globals')

How to Reproduce

I guess the reason is two versions of autodoc-typehint installed - not sure yet:

  • sphinx.ext.autodoc.type_comment (8.2.3)
  • sphinx_autodoc_typehints (unknown version)
SPHINXOPTS: "-v -W --keep-going"
$ sphinx-build $SPHINXOPTS --color -T -j "auto" -c . ./tmp "$CI_PROJECT_DIR"/out/"$DOC_TARGET_PATH" 2>&1 | tee "$CI_PROJECT_DIR"/out/sphinx.log

Environment Information

Loaded Extensions
=================
* sphinx.ext.mathjax (8.2.3)
* alabaster (1.0.0)
* sphinxcontrib.applehelp (2.0.0)
* sphinxcontrib.devhelp (2.0.0)
* sphinxcontrib.htmlhelp (2.1.0)
* sphinxcontrib.serializinghtml (2.0.0)
* sphinxcontrib.qthelp (2.0.0)
* sphinx.ext.autodoc.preserve_defaults (8.2.3)
* sphinx.ext.autodoc.type_comment (8.2.3)
* sphinx.ext.autodoc.typehints (8.2.3)
* sphinx.ext.autodoc (8.2.3)
* sphinx_autodoc_typehints (unknown version)
* sphinx.ext.intersphinx (8.2.3)
* sphinx.ext.viewcode (8.2.3)
* sphinx.ext.coverage (8.2.3)
* sphinx_book_theme (unknown version)
* pydata_sphinx_theme (unknown version)

Versions
========
* Platform:         linux; (Linux-5.10.0-25-cloud-amd64-x86_64-with-glibc2.36)
* Python version:   3.11.2 (CPython)
* Sphinx version:   8.2.3
* Docutils version: 0.21.2
* Jinja2 version:   3.1.6
* Pygments version: 2.19.2

Sphinx extensions

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions