python / python/mypy

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

Abierto
#16,786 0 comentarios 2 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

feature
Lenguaje dominante
Python
Estrellas
20.6k
Forks
3.3k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

No se nombra ningún archivo, prueba ni punto de entrada. Empieza localizando cómo mypy gestiona los parámetros de funciones sin tipo y las comprobaciones existentes relacionadas con underscore; darlo por terminado debería significar que un parámetro underscore puede omitir una anotación de tipo sin una advertencia, con el comportamiento previsto y cualquier opción de configuración aclarados.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
devtools
Tipo de issue
Nueva funcionalidad
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.