python / python/mypy

Option to remove unsupported annotations from `numpy.ndarray` and `List` in stubgen

Aperta
#12,992 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

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

Descrizione

Feature

Command-line arguments for stubgen that when enabled will remove unsupported annotations from numpy.ndarray and List
like numpy.ndarray[numpy.float32[3,1]] and List[float[3]] which pybind11 outputs.

FYI: This feature has been implemented for numpy.ndarray in pybind11-stubgen.

Pitch

The stubs generated from extensions made with pybind11 using mypy.stubs are invalid when Eigen types or std::array are used in the interface.

As an example, this output from stubgen,

    def as_numpy(self) -> numpy.ndarray[numpy.float32[3,1]]: ...

will give the following errors when used together with Mypy:

error: Bad number of arguments for type alias, expected: 0, given: 2
error: "ndarray" expects 2 type arguments, but 1 given
error: Invalid type: try using Literal[2] instead?
error: Invalid type: try using Literal[1] instead?

And this

def split(axis_aligned_bounding_box: AxisAlignedBoundingBox, max_extents: List[float[3]]) -> List[AxisAlignedBoundingBox]: ...

will give these errors:

error: "float" expects no type arguments, but 1 given
error: Invalid type: try using Literal[3] instead?

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

Inizia dal punto di ingresso da riga di comando di stubgen e segui il modo in cui vengono emesse annotazioni come numpy.ndarray[...] e List[...]. Aggiungi un’opzione che rimuova le annotazioni non supportate, quindi verifica che gli stub generati non producano più gli errori mypy descritti.

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

Valutazione

Stack tecnologico
numpy, python
Ambito
cli, devtools, tooling
Tipo di issue
Funzionalità
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.