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

Fix type hints in docs for PUBs and improve Sphinx config (Cherry-pick of #2052) #2055

Merged
merged 1 commit into from
Nov 25, 2024

Conversation

Eric-Arellano
Copy link
Collaborator

Closes #1877. We now use EstimatorPubLike and SamplerPubLike for the type hints, rather than Sphinx fully expanding the types into extremely long values shown in #1877.

To fix the type hints, we have to stop using sphinx-autodoc-typehints and instead use autodoc's builtin support for type hints. I didn't realize we were still using sphinx-autodoc-typehints - the other Qiskit projects migrated off a while ago.

This PR also makes some other improvements to align with changes we made in Qiskit Addons & qiskit-ibm-transpiler:

  • always show inheritance in class pages for the base class
  • index page should show the PyPI package name in code syntax
  • don't show signatures in autosummary tables, since they're noisy
  • show type hints for parameters that don't have docstring

Introduces a regression: type hints for properties

Unfortunately, switching off of sphinx-autodoc-typehints results in Qiskit/documentation#2346. This is a quirk of autosummary that we cannot easily fix. We have a plan to fix it, although realistically won't get to it until Q1 and possibly Q2.

In the meantime, consider repeating some of the type information in the docstring. For example, in

<Attribute id="qiskit_ibm_runtime.EstimatorV2.mode">
    Return the execution mode used by this primitive.

You could rewrite to say

<Attribute id="qiskit_ibm_runtime.EstimatorV2.mode">
    Return the execution mode used by this primitive, either :class:~`.Session` or ~:class:~`.Batch`.

Closes Qiskit#1877. We now use `EstimatorPubLike` and `SamplerPubLike` for the type hints, rather than Sphinx fully expanding the types into extremely long values shown in Qiskit#1877.

To fix the type hints, we have to stop using `sphinx-autodoc-typehints` and instead use autodoc's builtin support for type hints. I didn't realize we were still using `sphinx-autodoc-typehints` - the other Qiskit projects migrated off a while ago.

This PR also makes some other improvements to align with changes we made in Qiskit Addons & qiskit-ibm-transpiler:

* always show inheritance in class pages for the base class
* index page should show the PyPI package name in code syntax
* don't show signatures in `autosummary` tables, since they're noisy
* show type hints for parameters that don't have docstring

## Introduces a regression: type hints for properties

Unfortunately, switching off of `sphinx-autodoc-typehints` results in Qiskit/documentation#2346. This is a quirk of autosummary that we cannot easily fix. We have a plan to fix it, although realistically won't get to it until Q1 and possibly Q2.

In the meantime, consider repeating some of the type information in the docstring. For example, in

```
<Attribute id="qiskit_ibm_runtime.EstimatorV2.mode">
    Return the execution mode used by this primitive.
```

You could rewrite to say

```
<Attribute id="qiskit_ibm_runtime.EstimatorV2.mode">
    Return the execution mode used by this primitive, either :class:~`.Session` or ~:class:~`.Batch`.
```
@Eric-Arellano Eric-Arellano requested a review from kt474 November 25, 2024 15:48
@kt474 kt474 merged commit 91c59c5 into Qiskit:stable/0.33 Nov 25, 2024
19 checks passed
@Eric-Arellano Eric-Arellano deleted the EA/cp-sphinx-config branch November 25, 2024 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants