@@ -1914,20 +1914,28 @@ class so far, an alias named ``get_alias`` will be defined; the same will
1914
1914
if cls is None : # Return the actual class decorator.
1915
1915
return functools .partial (_define_aliases , alias_d )
1916
1916
1917
- def make_alias (name ): # Enforce a closure over *name*.
1918
- def method (self , * args , ** kwargs ):
1919
- return getattr (self , name )(* args , ** kwargs )
1920
- return method
1917
+ def make_alias (method ):
1918
+ import inspect
1919
+ args = str (inspect .signature (method ))[1 :- 1 ] # remove parentheses
1920
+ if args [:6 ] == 'self, ' :
1921
+ call_args = args [6 :]
1922
+ elif args == 'self' :
1923
+ call_args = ''
1924
+ else :
1925
+ raise RuntimeError ('Unexpected signature: %s' % args )
1926
+ alias_method = eval ('lambda {}: self.{}({})' .format (
1927
+ args , method .__name__ , call_args ))
1928
+ alias_method .__doc__ = "Alias for `{}`." .format (method .__name__ )
1929
+ return alias_method
1921
1930
1922
1931
for prop , aliases in alias_d .items ():
1923
1932
exists = False
1924
1933
for prefix in ["get_" , "set_" ]:
1925
1934
if prefix + prop in vars (cls ):
1926
1935
exists = True
1927
1936
for alias in aliases :
1928
- method = make_alias (prefix + prop )
1937
+ method = make_alias (getattr ( cls , prefix + prop ) )
1929
1938
method .__name__ = prefix + alias
1930
- method .__doc__ = "Alias for `{}`." .format (prefix + prop )
1931
1939
setattr (cls , prefix + alias , method )
1932
1940
if not exists :
1933
1941
raise ValueError (
0 commit comments