allow variables named `_` (underscore) to be untyped (throwaway variables)
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Keine Datei, kein Test und kein Einstiegspunkt werden genannt. Beginne damit, die Handhabung untypisierter Funktionsparameter durch mypy und bestehende Prüfungen im Zusammenhang mit underscore zu lokalisieren; als erledigt sollte gelten, dass ein underscore-Parameter einen Typ-Hinweis ohne Warnung auslassen kann und das beabsichtigte Verhalten sowie eine etwaige Konfigurationsoption geklärt sind.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100