Better message for "Function ... could always be true"
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 20.6k
- Forks
- 3.3k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
Consider this example:
def f(x: int) -> str: pass
if f:
pass
It generates this error:
t.py:3: error: Function "Callable[[int], str]" could always be true in boolean context [truthy-function]
Instead, if we have a direct reference to a function definition, we could generate a message like this which would be clearer, especially if the signature is complex:
t.py:3: error: Function "f" could always be true in boolean context [truthy-function]
There are at least these different cases to consider:
- Direct reference to a function using a short name of a function (similar to the above example).
- Direct reference to a function using a module prefix (e.g.
if mod.func:). - Reference to a method (e.g.
if obj.method:). - Reference to a variable/attribute (
Varnode) with typeCallable[...](in this case we could show the name of the variable/attribute or the callable type -- both would be okay). - Any other expression that produces a callable value, such as
if func():wherefuncreturns a callable. Here the best option is to show the callable type as we do now.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Empieza reproduciendo el ejemplo e inspecciona cómo el diagnóstico [truthy-function] formatea las expresiones invocables. Compara referencias directas a funciones, funciones calificadas por módulo, métodos, variables o atributos invocables y expresiones que devuelven objetos invocables. La tarea estará terminada cuando las referencias directas usen el nombre de función más claro cuando corresponda, mientras que los demás casos conserven un tipo o una descripción útil del objeto o la expresión invocable.
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
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 42/100