sphinx icon indicating copy to clipboard operation
sphinx copied to clipboard

autosummary drops all parameters of overloaded functions in the summary table

Open PRINCE2-AI opened this issue 1 month ago • 0 comments

Describe the bug

An @overload-decorated function or method is rendered in an autosummary table with every parameter missing, e.g. f (-> int) instead of an argument list. The cell suggests a zero-argument function, and only the return annotation of one overload survives.

To Reproduce

overloads_mod.py:

from typing import overload


@overload
def f(x: int) -> int: ...
@overload
def f(x: str, y: int = 1) -> str: ...
def f(x, y=1):
    """Two overloads."""

index.rst:

Test
====

.. autosummary::

   overloads_mod.f

Build with sphinx-build -b html . _build.

Actual output

The table cell renders as:

overloads_mod.f (-> int)

Depending on the overload set it can also collapse to overloads_mod.f ().

Expected output

Something that does not drop the parameters, e.g. overloads_mod.f (…), matching what :signatures: short already produces for multi-signature objects. The generated stub page renders the overloads correctly, so only the compact table cell is wrong.

Cause

Autosummary.get_items() joins every signature into one string and hands it to mangle_signature():

sig = mangle_signature('\n'.join(props.signatures), max_chars=max_chars)

mangle_signature() parses its argument with signature_from_str(), which raises SyntaxError on the multi-line joined string. The parameters list therefore stays empty and the regex fallback mangles the leftovers into (-> int).

For the example above the argument received is literally:

'(x: int) -> int\n(x: str, y: int = 1) -> str'

Additional context

Overloaded methods are affected the same way (m (-> int) inside the class page table). A single-signature function is unaffected, and :signatures: short is fine because it never reaches mangle_signature().

Environment

  • Sphinx 9.3.0 (dev, master @ 1ddf198)
  • Python 3.13
  • Builder: html

PRINCE2-AI avatar Oct 27 '26 06:10 PRINCE2-AI