python / python/mypy

`get_function_signature_hook` is not invoked on function decorators

Abierto
#21,904 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

bug topic-plugins
Lenguaje dominante
Python
Estrellas
20.6k
Forks
3.3k
Merge medio
1 d 18 h
PR fusionados (30 d)
54

Descripción

Bug Report

It seems to me there is no way to intercept and change the signature of a decorator during the invocation.

I see that get_function_hook has been called for foo.deco (eventually allowing me to change the return type of the decorator) but get_function_signature_hook is missing

To Reproduce

very basic example:

foo.py

from collections.abc import Callable
def deco(fun: Callable[..., None]) -> None: ...
@deco
def fun() -> None: ...

plug.py

from mypy.plugin import *
from mypy.types import *
from collections.abc import Callable

class CustomPlugin(Plugin):
    def get_function_hook(self, fullname: str) -> Callable[[FunctionContext], Type] | None:
        print(f'get_function_hook - {fullname=}')
        return None

    def get_function_signature_hook(self, fullname: str) -> Callable[[FunctionSigContext], FunctionLike] | None:
        print(f'get_function_signature_hook - {fullname=}')
        return None

def plugin(_version: str, /) -> type[Plugin]:
    return CustomPlugin

If I run mypy with the plugin and capture the stdout I get (avoiding the duplicates):

get_function_hook - fullname='enum.auto'
get_function_hook - fullname='foo.deco'
get_function_hook - fullname='<list>'
get_function_hook - fullname='typing_extensions.disjoint_base'
get_function_hook - fullname='typing_extensions.final'
get_function_hook - fullname='typing.final'
get_function_hook - fullname='typing.runtime_checkable'
get_function_hook - fullname='typing.type_check_only'
get_function_hook - fullname='warnings.deprecated'
get_function_signature_hook - fullname='enum.auto'
get_function_signature_hook - fullname='warnings.deprecate

Expected Behavior

get_function_signature_hook is called also for foo.deco

Actual Behavior

it's missing

Your Environment

mypy 2.3.1 (compiled: yes)
Python 3.14.0

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

Ejecuta mypy sobre la reproducción de foo.py con el plugin de plug.py y compara las llamadas a get_function_hook y get_function_signature_hook para foo.deco. Rastrea la ruta de despacho del plugin para la invocación del decorador y añade o actualiza la cobertura para que se invoque el signature hook para foo.deco; se considera terminado cuando aparece el callback esperado sin romper el comportamiento existente de los hooks.

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

Evaluación

Stack tecnológico
python
Área
compilers, devtools
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Activo
Claridad
Bastante claro
Aptitud para principiantes
52/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.