11import functools
2+ import inspect
23
34from typing import List , Union
45
@@ -24,8 +25,26 @@ def decorator(func):
2425 normalized_methods = [methods ] if isinstance (methods , str ) else methods
2526 func ._api_methods = normalized_methods
2627
28+ # Get the signature of the original function ONCE
29+ sig = inspect .signature (func )
30+
2731 @functools .wraps (func )
2832 def wrapper (self , * args , ** kwargs ):
33+
34+ try :
35+ bound_args = sig .bind (* args , ** kwargs )
36+ except TypeError :
37+ # If arguments don't match signature, let the actual func raise the error
38+ return func (* args , ** kwargs )
39+
40+ arguments = bound_args .arguments
41+
42+ # Robustly find 'self' (it's usually the first argument in bound_args)
43+ # We look for the first value in arguments, or try to get 'self' explicitly.
44+ instance = arguments .get ("self" )
45+ if not instance and args :
46+ instance = args [0 ]
47+
2948 # Retrieve the Spec from the instance
3049 # We assume 'self' has a .specs attribute (like DocstringPatcher expects)
3150 spec = getattr (self , "specs" , {}).get (spec_name )
@@ -43,14 +62,13 @@ def wrapper(self, *args, **kwargs):
4362 spec = spec ,
4463 path = path ,
4564 method = current_method ,
46- parameters = kwargs ,
65+ parameters = arguments ,
4766 )
4867 except ValueError as e :
49- # Optional: Log the error or re-raise custom exception
5068 print (f"[Validation Error] { e } " )
5169 raise e
5270
53- # 5. Proceed with the original function call
71+ # Proceed with the original function call
5472 return func (* args , ** kwargs )
5573
5674 # Copy tags to wrapper for the DocstringPatcher to find
0 commit comments