Skip to content

_stringify_annotation patch breaks in Sphinx==8.2.0 #523

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

Closed
b-kamphorst opened this issue Feb 17, 2025 · 1 comment · Fixed by #525
Closed

_stringify_annotation patch breaks in Sphinx==8.2.0 #523

b-kamphorst opened this issue Feb 17, 2025 · 1 comment · Fixed by #525

Comments

@b-kamphorst
Copy link
Contributor

b-kamphorst commented Feb 17, 2025

Hi!

I just tested sphinx-autodoc-typehints==3.0.1 against the release candidate sphinx==8.2.0rc1 and it breaks. Reason is that the signature of stringify_annotation got an additional (keyword-only) parameter short_literals, which is not accepted by sphinx-autodoc-typehints patched version named _stringify_annotation.

An easy but inelegant fix would be to accept and ignore any *args and **kwargs, but I'm not sufficiently familiar with this repo to know whether you actually need to do something with the new argument.

Full traceback
Traceback
=========

    Traceback (most recent call last):
      File "/usr/local/lib/python3.12/site-packages/sphinx/cmd/build.py", line 432, in build_main
        app.build(args.force_all, args.filenames)
      File "/usr/local/lib/python3.12/site-packages/sphinx/application.py", line 426, in build
        self.builder.build_update()
      File "/usr/local/lib/python3.12/site-packages/sphinx/builders/__init__.py", line 375, in build_update
        self.build(
      File "/usr/local/lib/python3.12/site-packages/sphinx/builders/__init__.py", line 403, in build
        updated_docnames = set(self.read())
                               ^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/sphinx/builders/__init__.py", line 519, in read
        self._read_serial(docnames)
      File "/usr/local/lib/python3.12/site-packages/sphinx/builders/__init__.py", line 584, in _read_serial
        self.read_doc(docname)
      File "/usr/local/lib/python3.12/site-packages/sphinx/builders/__init__.py", line 648, in read_doc
        publisher.publish()
      File "/usr/local/lib/python3.12/site-packages/docutils/core.py", line 234, in publish
        self.document = self.reader.read(self.source, self.parser,
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/sphinx/io.py", line 103, in read
        self.parse()
      File "/usr/local/lib/python3.12/site-packages/docutils/readers/__init__.py", line 76, in parse
        self.parser.parse(self.input, document)
      File "/usr/local/lib/python3.12/site-packages/sphinx/parsers.py", line 86, in parse
        self.statemachine.run(inputlines, document, inliner=self.inliner)
      File "/usr/local/lib/python3.12/site-packages/docutils/parsers/rst/states.py", line 169, in run
        results = StateMachineWS.run(self, input_lines, input_offset,
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/docutils/statemachine.py", line 233, in run
        context, next_state, result = self.check_line(
                                      ^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/docutils/statemachine.py", line 445, in check_line
        return method(match, context, next_state)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/docutils/parsers/rst/states.py", line 2790, in underline
        self.section(title, source, style, lineno - 1, messages)
      File "/usr/local/lib/python3.12/site-packages/docutils/parsers/rst/states.py", line 325, in section
        self.new_subsection(title, lineno, messages)
      File "/usr/local/lib/python3.12/site-packages/docutils/parsers/rst/states.py", line 391, in new_subsection
        newabsoffset = self.nested_parse(
                       ^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-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.12/site-packages/docutils/parsers/rst/states.py", line 195, in run
        results = StateMachineWS.run(self, input_lines, input_offset)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/docutils/statemachine.py", line 233, in run
        context, next_state, result = self.check_line(
                                      ^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/docutils/statemachine.py", line 445, in check_line
        return method(match, context, next_state)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/docutils/parsers/rst/states.py", line 2357, in explicit_markup
        nodelist, blank_finish = self.explicit_construct(match)
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/docutils/parsers/rst/states.py", line 2369, in explicit_construct
        return method(self, expmatch)
               ^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/docutils/parsers/rst/states.py", line 2106, in directive
        return self.run_directive(
               ^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/docutils/parsers/rst/states.py", line 2156, in run_directive
        result = directive_instance.run()
                 ^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/sphinx/ext/autodoc/directive.py", line 175, in run
        documenter.generate(more_content=self.content)
      File "/usr/local/lib/python3.12/site-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.12/site-packages/sphinx/ext/autodoc/__init__.py", line 1121, in _generate
        self.document_members(all_members)
      File "/usr/local/lib/python3.12/site-packages/sphinx/ext/autodoc/__init__.py", line 968, in document_members
        documenter._generate(
      File "/usr/local/lib/python3.12/site-packages/sphinx/ext/autodoc/__init__.py", line 1121, in _generate
        self.document_members(all_members)
      File "/usr/local/lib/python3.12/site-packages/sphinx/ext/autodoc/__init__.py", line 2119, in document_members
        super().document_members(all_members)
      File "/usr/local/lib/python3.12/site-packages/sphinx/ext/autodoc/__init__.py", line 968, in document_members
        documenter._generate(
      File "/usr/local/lib/python3.12/site-packages/sphinx/ext/autodoc/__init__.py", line 1121, in _generate
        self.document_members(all_members)
      File "/usr/local/lib/python3.12/site-packages/sphinx/ext/autodoc/__init__.py", line 2119, in document_members
        super().document_members(all_members)
      File "/usr/local/lib/python3.12/site-packages/sphinx/ext/autodoc/__init__.py", line 968, in document_members
        documenter._generate(
      File "/usr/local/lib/python3.12/site-packages/sphinx/ext/autodoc/__init__.py", line 1111, in _generate
        self.add_directive_header(sig)
      File "/usr/local/lib/python3.12/site-packages/sphinx_autodoc_typehints/attributes_patch.py", line 58, in add_directive_header
        return orig_add_directive_header(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/site-packages/sphinx/ext/autodoc/__init__.py", line 2980, in add_directive_header
        objrepr = stringify_annotation(
                  ^^^^^^^^^^^^^^^^^^^^^
    TypeError: _stringify_annotation() got an unexpected keyword argument 'short_literals'

Release plan for 8.2.0: sphinx-doc/sphinx#13325.

@b-kamphorst
Copy link
Contributor Author

sphinx==8.2.0 is released and indeed incompatible with sphinx-autodoc-typehints==3.0.1.

@b-kamphorst b-kamphorst changed the title _stringify_annotation patch breaks in Sphinx==8.2.0rc1 _stringify_annotation patch breaks in Sphinx==8.2.0 Feb 18, 2025
jodal added a commit to jodal/mopidy that referenced this issue Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants