From 62a397b7c50699ca0a0d6fdb308cb4996178c5cc Mon Sep 17 00:00:00 2001 From: Junhwan Kim Date: Thu, 13 Nov 2025 06:00:02 +0000 Subject: [PATCH] inspect: support get_original_fn for class method When a method decorated with DecoratorBase is accessed via Class.method or instance.method, Python's descriptor protocol automatically calls DecoratorBase.__get__(), which returns DecoratorBinder object. One example is marking a class method by `asynq` (https://github.com/quora/asynq) --- qcore/inspection.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/qcore/inspection.py b/qcore/inspection.py index 0d66005..c4b2cd8 100644 --- a/qcore/inspection.py +++ b/qcore/inspection.py @@ -39,6 +39,12 @@ def get_original_fn(fn): except AttributeError: pass return original_fn + # Handle DecoratorBinder objects (e.g., AsyncDecoratorBinder) + # When a method decorated with DecoratorBase is accessed via Class.method or instance.method, + # Python's descriptor protocol automatically calls DecoratorBase.__get__(), which returns + # DecoratorBinder object. Get original function from DecoratorBinder -> .decorator -> .fn + if hasattr(fn, "decorator") and hasattr(fn.decorator, "fn"): + return get_original_fn(fn.decorator.fn) return fn