@@ -441,6 +441,64 @@ def fn(**_):
441441 assert handlers [0 ].new is None
442442
443443
444+ def test_explicit_instance_methods (resource , cause_factory ):
445+ registry = OperatorRegistry ()
446+ cause = cause_factory (resource = resource , reason = Reason .CREATE )
447+
448+ class TestCls :
449+ def fn (self , ** _ ):
450+ pass
451+
452+ obj1 = TestCls ()
453+ kopf .on .create (* resource , registry = registry )(obj1 .fn )
454+
455+ handlers = registry ._changing .get_handlers (cause )
456+ assert len (handlers ) == 1
457+ assert handlers [0 ].fn == obj1 .fn # a bound method
458+
459+
460+ def test_explicit_subclass_methods (resource , cause_factory ):
461+ registry = OperatorRegistry ()
462+ cause = cause_factory (resource = resource , reason = Reason .CREATE )
463+
464+ class BaseCls :
465+ @classmethod
466+ def fn (cls , ** _ ):
467+ pass
468+
469+ class TestCls (BaseCls ):
470+ pass
471+
472+ kopf .on .create (* resource , registry = registry )(TestCls .fn )
473+
474+ handlers = registry ._changing .get_handlers (cause )
475+ assert len (handlers ) == 1
476+ assert handlers [0 ].fn != BaseCls .fn # an improperly bound method
477+ assert handlers [0 ].fn == TestCls .fn # a properly bound method
478+
479+
480+ def test_explicit_static_methods (resource , cause_factory ):
481+ registry = OperatorRegistry ()
482+ cause = cause_factory (resource = resource , reason = Reason .CREATE )
483+
484+ class BaseCls :
485+ @staticmethod
486+ def fn (cls , ** _ ):
487+ pass
488+
489+ class TestCls (BaseCls ):
490+ pass
491+
492+ obj = TestCls ()
493+ kopf .on .create (* resource , registry = registry )(obj .fn )
494+
495+ handlers = registry ._changing .get_handlers (cause )
496+ assert len (handlers ) == 1
497+ assert handlers [0 ].fn == BaseCls .fn # an improperly bound method
498+ assert handlers [0 ].fn == TestCls .fn # a properly bound method
499+ assert handlers [0 ].fn == obj .fn # a properly bound method
500+
501+
444502def test_subhandler_fails_with_no_parent_handler ():
445503
446504 registry = ChangingRegistry ()
0 commit comments