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

PEP 646-style annotation of *args as a Type Variable Tuple #13368

Open
agraboso opened this issue Feb 19, 2025 · 0 comments · May be fixed by #13369
Open

PEP 646-style annotation of *args as a Type Variable Tuple #13368

agraboso opened this issue Feb 19, 2025 · 0 comments · May be fixed by #13369
Labels
Milestone

Comments

@agraboso
Copy link

agraboso commented Feb 19, 2025

Describe the bug

The simple

.. py.function:: func(*args: *tuple[str, int])

emits a warning

WARNING: could not parse arglist ('*args: *tuple[int, str]'): Unable to parse Starred object

The culprit is the absence of a visit_Starred method in the class sphinx.pycode.ast._UnparseVisitor. After fixing that with the inclusion of

def visit_Starred(self, node: ast.Starred) -> str:
    return f'*{self.visit(node.value)}'

a further warning is emitted:

WARNING: py:class reference target not found: *tuple[int, str] [ref.class]

In this case the problem is that sphinx.domains.python._annotations._parse_annotation tries to find a cross-reference without first splitting off the star in front. A solution is the inclusion of the following block in the body of the unparse function within that function:

if isinstance(node, ast.Starred):
    result = [addnodes.desc_sig_operator('', '*')]
    result.extend(unparse(node.value))
    return result

PR to follow.

How to Reproduce

index.rst:

.. py.function:: func(*args: *tuple[str, int]

conf.py:

extensions = [
    "sphinx.ext.intersphinx",
]
intersphinx_mapping = {
    "python": ("https://docs.python.org/3/", None),
}

Environment Information

Platform:              darwin; (macOS-14.7-arm64-arm-64bit-Mach-O)
Python version:        3.13.1 (main, Dec  3 2024, 17:59:52) [Clang 15.0.0 (clang-1500.3.9.4)])
Python implementation: CPython
Sphinx version:        8.2.0
Docutils version:      0.21.2
Jinja2 version:        3.1.5
Pygments version:      2.19.1

Sphinx extensions

["sphinx.ext.intersphinx"]

Additional context

None.

@AA-Turner AA-Turner added this to the 8.x milestone Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants