Use of generics in requests typing
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 5.1k
- Fork
- 2.1k
- Merge medio
- 1g 19h
- PR unite (30g)
- 82
Descrizione
Currently the requests typing makes heavy use of unions. For example the parameter type is:
https://github.com/python/typeshed/blob/f99e8b0615182bb0f17d9d126019d8d72c207ab3/stubs/requests/requests/sessions.pyi#L97-L103
The issue with this approach is that the type system can't keep track of which type has been chosen for a given field. For example, running pyright on this code:
from requests import Session
session = Session()
session.params = {}
reveal_type(session.params)
Shows us that the type system immediately "forgets" that our parameters are definitely in a dictionary:
test.py:5:13 - information: Type of "session.params" is "dict[str | bytes | int | float, str | bytes | int | float | Iterable[str | bytes | int | float] | None]"
0 errors, 0 warnings, 1 information
If we could make Session (as well as other classes such as Request) generic over the parameter type (as well as other fields), then we could keep track of this kind of state. For example, it might look like:
session: Session[dict] = Session()
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
Inizia con la sezione collegata di requests/requests/sessions.pyi intorno alle righe 97-103, quindi esamina come sono tipizzati Session e Request. Usa l’esempio pyright fornito per valutare se i tipi dei parametri generici rimangono specifici dopo un’assegnazione; il lavoro è completato quando il design generico proposto è definito in modo coerente per le classi interessate e conserva i tipi dei campi selezionati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- tooling
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100