From c7c6c5fde5f7d5f17b41a2e15c16305880508721 Mon Sep 17 00:00:00 2001 From: cherith <315844584+Cherith1222@users.noreply.github.com> Date: Tue, 6 Oct 2026 11:34:38 +0800 Subject: [PATCH 1/2] Call function signature hooks when checking decorators. Decorator calls never reached get_function_signature_hook, so a plugin could not adjust that signature the way a normal call can. AI-assisted (Cursor); not yet reviewed. --- mypy/checker.py | 10 ++++++++++ test-data/unit/check-custom-plugin.test | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/mypy/checker.py b/mypy/checker.py index 03120d18b073..af16fad5b2ef 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -5911,6 +5911,16 @@ def visit_decorator_inner( object_type = self.lookup_type(d.expr) fullname = self.expr_checker.method_fullname(object_type, d.name) self.check_for_untyped_decorator(e.func, dec, d) + # check_call does not apply signature hooks; do that here, as for other calls. + if fullname: + dec = self.expr_checker.transform_callee_type( + fullname, + dec, + [temp], + [nodes.ARG_POS], + e, + object_type=object_type, + ) sig, t2 = self.expr_checker.check_call( dec, [temp], [nodes.ARG_POS], e, callable_name=fullname, object_type=object_type ) diff --git a/test-data/unit/check-custom-plugin.test b/test-data/unit/check-custom-plugin.test index 504c15314553..31ac9f851025 100644 --- a/test-data/unit/check-custom-plugin.test +++ b/test-data/unit/check-custom-plugin.test @@ -908,6 +908,19 @@ reveal_type(dynamic_signature(b)) # N: Revealed type is "builtins.bytes" \[mypy] plugins=/test-data/unit/plugins/function_sig_hook.py +[case testFunctionSigHookCalledOnDecorator] +# flags: --config-file tmp/mypy.ini + +def dynamic_signature(arg1: str) -> str: ... + +@dynamic_signature +def f() -> int: ... + +reveal_type(f) # N: Revealed type is "def () -> builtins.int" +[file mypy.ini] +\[mypy] +plugins=/test-data/unit/plugins/function_sig_hook.py + [case testPluginCalledCorrectlyWhenMethodInDecorator] # flags: --config-file tmp/mypy.ini from typing import TypeVar, Callable From 0eb0a693c483e6e789751b09636e097179f84809 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 7 Oct 2026 07:15:55 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mypy/checker.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/mypy/checker.py b/mypy/checker.py index af16fad5b2ef..f762ad860ca6 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -5914,12 +5914,7 @@ def visit_decorator_inner( # check_call does not apply signature hooks; do that here, as for other calls. if fullname: dec = self.expr_checker.transform_callee_type( - fullname, - dec, - [temp], - [nodes.ARG_POS], - e, - object_type=object_type, + fullname, dec, [temp], [nodes.ARG_POS], e, object_type=object_type ) sig, t2 = self.expr_checker.check_call( dec, [temp], [nodes.ARG_POS], e, callable_name=fullname, object_type=object_type