Support multi-statement inference for custom types
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Feature
Multi-statement inference as proposed in #254 and #1055 is supported for empty standard collection classes, like dict or list, but not for custom classes. Thus, an example such as https://mypy-play.net/?mypy=latest&python=3.10&gist=7df00fc3d8612804369dbad6b5cb973b fails.
My proposal is to allow user-defined generics to infer the generic from their first usage, so that the example work.
Pitch
This problem arose in the context of making a typed library compatible with scikit-learn (which currently is not typed). In scikit-learn, the actual data of a machine learning problem is not passed to the constructor of the object, but instead passed to the fit method (for training). Thus, if one wants to make a scikit-learn compatible object which is generic over the data accepted, one currently needs to provide the annotation, as Mypy won't infer the generic type from the call to fit. This is cumbersome for users, as most of them should benefit from the typing without altering the code to add superfluous annotations. It also obscures the examples, as adding annotations would confuse users not used to them.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
L’issue non indica alcun file o test del repository. Riproduci l’esempio mypy-play collegato, quindi confronta il comportamento di custom-generic con l’inferenza esistente su più istruzioni per dict e list vuoti; il lavoro è completato quando custom-generic viene inferito dal suo primo utilizzo e la copertura di regressione verifica l’esempio.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python, scikit-learn
- Ambito
- devtools
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 30/100