python / python/mypy

allow variables named `_` (underscore) to be untyped (throwaway variables)

Aperta
#16,786 0 commenti 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

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

Descrizione

Feature

There is a very common practice in python, to use the underscore character - _ - as a variable name for a "throwaway character" - mostly when receiving function output values that will not be used, or when implementing functions with defined signatures, without using some of the variables.

The feature request is to allow these variables to be without type hints, and do not warn.

Pitch

In our company, we work a lot with web development, APIs and such, and it is very common to have to implement predefined function signatures. For example, when using AWS lambdas, one needs to implement:
def lambda_handler(event, context):

However, it is very common to only use the event parameter in the code, and not the context - meaning many times we implement
def lambda_handler(event, _):

when typing the function, I currently do something like this

from typing import Any
def lambda_handler(event: dict, _: Any) -> None:

since I do not necessarily know what the _/context variable type is, and I do not care to invest work in finding it when the variable is not in use. It would be easier and nicer if I could simply do this
def lambda_handler(event: dict, _) -> None:

There are plenty of other examples, similar to this, and so I am sure this feature can be useful to many other people. I think even if the feature were to be configurable with a flag (allow_untyped_underscore or something) that would be very helpful as well.

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

Non vengono indicati file, test o punti di ingresso. Inizia individuando la gestione da parte di mypy dei parametri di funzione senza tipo e dei controlli esistenti relativi a underscore; considerare il lavoro completato dovrebbe significare che un parametro underscore può omettere un’annotazione di tipo senza un avviso, con il comportamento previsto e qualsiasi opzione di configurazione chiariti.

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

Valutazione

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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.