function is lacking a `__signature__` attribute
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 5.1k
- Forks
- 2.1k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 82
Descripción
PEP-362 specifies that in order to cache the signature of any function, it is possible for the user to set its __signature__ attribute.
Actual
This attribute is not set in the builtins module over at https://github.com/python/typeshed/blob/main/stdlib/builtins.pyi#L1009
As a result a typechecker might reject the following piece of code
from inspect import signature
def main():
def f():
pass
f.__signature__ = signature(f)
if __name__ == "__main__":
main()
e.g. with pyright I have a false positive
/Users/leogermond/Lab/python/signature/main.py
/Users/leogermond/Lab/python/signature/main.py:9:7 - error: Cannot assign to attribute "__signature__" for class "function"
Attribute "__signature__" is unknown (reportFunctionMemberAccess)
1 error, 0 warnings, 0 informations
Expected
I would the __signature__ attribute to be specified in the function class (with a special marker indicating it's optional?) of the builtins module. A type checker such as pyright could then infer that setting this attribute is possible and accept the piece of code given in example.
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
Comienza en stdlib/builtins.pyi, alrededor de la línea 1009, e inspecciona cómo se declara la function class. Compara la compatibilidad opcional solicitada para signature con PEP 362 y con el ejemplo de asignación proporcionado; después, verifica que un comprobador de tipos como pyright la acepte cuando el cambio del stub esté completo.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- tooling
- Tipo de issue
- Error
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 55/100