python / python/mypy

[Stubgenc] Fails to generate stub for Tuple special cases when using pybind11

Open
#17,394 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-stubgen
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Bug Report

Using pybind11 v2.12.0 allows adding typing annotations for things. And it works great for most types but fails to properly parse the tuple special cases and so the stub is left without a type.

To Reproduce

I discovered while contributing to the pybind11 project.
I would recommend following there guide to building.
Once built move into the build/tests directory
And run the following command

stubgen -p pybind11_tests

Expected Behavior

Generate the following.

def annotate_tuple_empty(arg0: tuple[()]) -> None: ...
def annotate_tuple_variable_length(arg0: tuple[float, ...]) -> None: ...

Actual Behavior

Generated the following.

def annotate_tuple_empty(arg0) -> None: ...
def annotate_tuple_variable_length(arg0) -> None: ...

Your Environment

  • Mypy version used:
    mypy 1.10.0 (compiled: yes)
  • Mypy command-line flags:
    Inside pybind11/build/tests
stubgen -p pybind11_tests
  • Python version used:
    Python3.10

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 in the stubgen path that handles pybind11-generated annotations, reproducing the issue from the pybind11 build/tests directory with stubgen -p pybind11_tests. Compare the generated output for annotate_tuple_empty and annotate_tuple_variable_length with the expected tuple annotations; done means both signatures retain their tuple types.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.