File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff 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
96107class TestHookDecoratorUnionTypes :
97108 """Tests for union type support in @hook decorator."""
You can’t perform that action at this time.
0 commit comments