python / python/mypy

stubgen & pybind11: can we make them play nice(r)?

Aperta
#16,306 24 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug topic-stubgen
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Bug Report
We're experimenting under https://github.com/pybind/pybind11/pull/4888 with a pybind11 behavior change, to generate

Annotated[Any, CppTypePybind11("cpp_namespace::UserType")]

instead of a bare cpp_namespace::UserType.

It seems like mypy does handle outer-level Annotated, but not nested ones, e.g.

Iterator[str, Annotated[Any, CppTypePybind11("cpp_namespace::UserType")]]

The results from stubgen (1.5.1, Google-internal toolchain) are like this:

def values(self, *args, **kwargs) -> Any: ...

Desired is:

def values(self) -> Iterator[str, Annotated[Any, CppTypePybind11("cpp_namespace::UserType")]]: ...

Does this ring any bells?

If you need more details, please let me know. (Note though that I don't know a lot about typing and mypy. This fell into my lap as Google-internal pybind11 owner & pybind11 maintainer on github.)

A more general question: What are your thought about changing the pybind11 behavior in this way? Is there a better way?

(A clear and concise description of what the bug is.)

To Reproduce

# Ideally, a small sample program that demonstrates the problem.
# Or even better, a reproducible playground link https://mypy-play.net/ (use the "Gist" button)

Expected Behavior

Actual Behavior

Your Environment

  • Mypy version used: 1.5.1, Google-internal toolchain
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.10

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Il report cita stubgen e mostra un esempio Annotated annidato, ma non contiene file del repository né test. Inizia riproducendo il comportamento con l’esempio Python 3.10 mostrato e stubgen 1.5.1, quindi traccia il punto in cui la firma diventa *args, **kwargs. Il lavoro è completato quando l’output generato conserva i tipi Iterator e Annotated annidati come nella firma desiderata.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
tooling
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
42/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.