Skip to content

Commit 0878e79

Browse files
committed
fix: ignore self and cls from method params
1 parent cb098d6 commit 0878e79

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

src/strands/hooks/_type_inference.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ def infer_event_types(callback: "HookCallback[TEvent]") -> "list[type[TEvent]]":
4444
if not params:
4545
raise ValueError("callback has no parameters | cannot infer event type, please provide event_type explicitly")
4646

47-
# Skip 'self' parameter for methods
47+
# Skip 'self' and 'cls' parameters for methods
4848
first_param = params[0]
49-
if first_param.name == "self" and len(params) > 1:
49+
if first_param.name in ("self", "cls") and len(params) > 1:
5050
first_param = params[1]
5151

5252
type_hint = hints.get(first_param.name)

tests/strands/plugins/test_hook_decorator.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,17 @@ def handler3(event: AfterInvocationEvent):
9292
assert AfterModelCallEvent in handler2._hook_event_types
9393
assert AfterInvocationEvent in handler3._hook_event_types
9494

95+
def test_hook_skips_cls_parameter(self):
96+
"""Test that @hook skips 'cls' parameter for classmethods."""
97+
98+
class MyClass:
99+
@classmethod
100+
@hook
101+
def handler(cls, event: BeforeModelCallEvent):
102+
pass
103+
104+
assert BeforeModelCallEvent in MyClass.handler._hook_event_types
105+
95106

96107
class TestHookDecoratorUnionTypes:
97108
"""Tests for union type support in @hook decorator."""

0 commit comments

Comments
 (0)