PyO3 / PyO3/pyo3

`text_signature` with enum default arguments cannot be processed by Sphinx

Open
#2,920 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
16.2k
Forks
1k
Avg merge
2d 6h
Merged PRs (30d)
66

Description

We are using Sphinx to generate the documentation for our Python package that we build using pyO3.
With the latest changes to signature and text_signature, we wanted to properly document default values for function and method arguments, including enum arguments.

For example, we added a text signature like text_signature ="(a=MyEnum.Variant1)" where MyEnum is a Rust enum and pyclass. Sphinx (autodoc) is not able to parse these signatures - it crashes with an exception:

<function record_typehints at 0x7f90007ed3a0> for event 'autodoc-process-signature' threw an exception (exception: )

I wasn't able to figure out what exactly goes wrong here. If this is not an issue of PyO3 but Sphinx, feel free to close this issue.
I'd be grateful for help or ideas to resolve this. For now, we removed the defaults in text_signature (signature works fine) but that's not an ideal solution.

I built a small crate that reproduces the error here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked test crate and the interaction between signature, text_signature, and Sphinx's autodoc-process-signature event. Compare how ordinary defaults and enum defaults are handled; done means Sphinx can process the enum default without raising the reported exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
documentation
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.