##// END OF EJS Templates
Update function attribute names...
Thomas Kluyver -
Show More
@@ -195,14 +195,14 b' def _method_magic_marker(magic_kind):'
195 if callable(arg):
195 if callable(arg):
196 # "Naked" decorator call (just @foo, no args)
196 # "Naked" decorator call (just @foo, no args)
197 func = arg
197 func = arg
198 name = func.func_name
198 name = func.__name__
199 retval = decorator(call, func)
199 retval = decorator(call, func)
200 record_magic(magics, magic_kind, name, name)
200 record_magic(magics, magic_kind, name, name)
201 elif isinstance(arg, string_types):
201 elif isinstance(arg, string_types):
202 # Decorator called with arguments (@foo('bar'))
202 # Decorator called with arguments (@foo('bar'))
203 name = arg
203 name = arg
204 def mark(func, *a, **kw):
204 def mark(func, *a, **kw):
205 record_magic(magics, magic_kind, name, func.func_name)
205 record_magic(magics, magic_kind, name, func.__name__)
206 return decorator(call, func)
206 return decorator(call, func)
207 retval = mark
207 retval = mark
208 else:
208 else:
@@ -240,7 +240,7 b' def _function_magic_marker(magic_kind):'
240 if callable(arg):
240 if callable(arg):
241 # "Naked" decorator call (just @foo, no args)
241 # "Naked" decorator call (just @foo, no args)
242 func = arg
242 func = arg
243 name = func.func_name
243 name = func.__name__
244 ip.register_magic_function(func, magic_kind, name)
244 ip.register_magic_function(func, magic_kind, name)
245 retval = decorator(call, func)
245 retval = decorator(call, func)
246 elif isinstance(arg, string_types):
246 elif isinstance(arg, string_types):
@@ -426,7 +426,7 b' class MagicsManager(Configurable):'
426 # Create the new method in the user_magics and register it in the
426 # Create the new method in the user_magics and register it in the
427 # global table
427 # global table
428 validate_type(magic_kind)
428 validate_type(magic_kind)
429 magic_name = func.func_name if magic_name is None else magic_name
429 magic_name = func.__name__ if magic_name is None else magic_name
430 setattr(self.user_magics, magic_name, func)
430 setattr(self.user_magics, magic_name, func)
431 record_magic(self.magics, magic_kind, magic_name, func)
431 record_magic(self.magics, magic_kind, magic_name, func)
432
432
@@ -193,8 +193,8 b' def getargspec(obj):'
193 func_obj = obj.__call__
193 func_obj = obj.__call__
194 else:
194 else:
195 raise TypeError('arg is not a Python function')
195 raise TypeError('arg is not a Python function')
196 args, varargs, varkw = inspect.getargs(func_obj.func_code)
196 args, varargs, varkw = inspect.getargs(func_obj.__code__)
197 return args, varargs, varkw, func_obj.func_defaults
197 return args, varargs, varkw, func_obj.__defaults__
198
198
199
199
200 def format_argspec(argspec):
200 def format_argspec(argspec):
@@ -198,7 +198,7 b' def findsource(object):'
198 if ismethod(object):
198 if ismethod(object):
199 object = object.im_func
199 object = object.im_func
200 if isfunction(object):
200 if isfunction(object):
201 object = object.func_code
201 object = object.__code__
202 if istraceback(object):
202 if istraceback(object):
203 object = object.tb_frame
203 object = object.tb_frame
204 if isframe(object):
204 if isframe(object):
@@ -136,7 +136,7 b' class FunctionMaker(object):'
136 func.__name__ = self.name
136 func.__name__ = self.name
137 func.__doc__ = getattr(self, 'doc', None)
137 func.__doc__ = getattr(self, 'doc', None)
138 func.__dict__ = getattr(self, 'dict', {})
138 func.__dict__ = getattr(self, 'dict', {})
139 func.func_defaults = getattr(self, 'defaults', ())
139 func.__defaults__ = getattr(self, 'defaults', ())
140 func.__kwdefaults__ = getattr(self, 'kwonlydefaults', None)
140 func.__kwdefaults__ = getattr(self, 'kwonlydefaults', None)
141 func.__annotations__ = getattr(self, 'annotations', None)
141 func.__annotations__ = getattr(self, 'annotations', None)
142 callermodule = sys._getframe(3).f_globals.get('__name__', '?')
142 callermodule = sys._getframe(3).f_globals.get('__name__', '?')
@@ -200,7 +200,7 b' def decorator(caller, func=None):'
200 decorator(caller, func) decorates a function using a caller.
200 decorator(caller, func) decorates a function using a caller.
201 """
201 """
202 if func is not None: # returns a decorated function
202 if func is not None: # returns a decorated function
203 evaldict = func.func_globals.copy()
203 evaldict = func.__globals__.copy()
204 evaldict['_call_'] = caller
204 evaldict['_call_'] = caller
205 evaldict['_func_'] = func
205 evaldict['_func_'] = func
206 return FunctionMaker.create(
206 return FunctionMaker.create(
@@ -211,7 +211,7 b' def decorator(caller, func=None):'
211 return partial(decorator, caller)
211 return partial(decorator, caller)
212 # otherwise assume caller is a function
212 # otherwise assume caller is a function
213 first = inspect.getargspec(caller)[0][0] # first arg
213 first = inspect.getargspec(caller)[0][0] # first arg
214 evaldict = caller.func_globals.copy()
214 evaldict = caller.__globals__.copy()
215 evaldict['_call_'] = caller
215 evaldict['_call_'] = caller
216 evaldict['decorator'] = decorator
216 evaldict['decorator'] = decorator
217 return FunctionMaker.create(
217 return FunctionMaker.create(
@@ -56,7 +56,7 b' class dependent(object):'
56
56
57 def __init__(self, f, df, *dargs, **dkwargs):
57 def __init__(self, f, df, *dargs, **dkwargs):
58 self.f = f
58 self.f = f
59 self.func_name = getattr(f, '__name__', 'f')
59 self.__name__ = getattr(f, '__name__', 'f')
60 self.df = df
60 self.df = df
61 self.dargs = dargs
61 self.dargs = dargs
62 self.dkwargs = dkwargs
62 self.dkwargs = dkwargs
@@ -71,7 +71,7 b' class dependent(object):'
71 if not py3compat.PY3:
71 if not py3compat.PY3:
72 @property
72 @property
73 def __name__(self):
73 def __name__(self):
74 return self.func_name
74 return self.__name__
75
75
76 @interactive
76 @interactive
77 def _require(*modules, **mapping):
77 def _require(*modules, **mapping):
@@ -52,7 +52,7 b' from .dependency import Dependency'
52 @decorator
52 @decorator
53 def logged(f,self,*args,**kwargs):
53 def logged(f,self,*args,**kwargs):
54 # print ("#--------------------")
54 # print ("#--------------------")
55 self.log.debug("scheduler::%s(*%s,**%s)", f.func_name, args, kwargs)
55 self.log.debug("scheduler::%s(*%s,**%s)", f.__name__, args, kwargs)
56 # print ("#--")
56 # print ("#--")
57 return f(self,*args, **kwargs)
57 return f(self,*args, **kwargs)
58
58
@@ -95,7 +95,7 b' class DocTestFinder(doctest.DocTestFinder):'
95 if module is None:
95 if module is None:
96 return True
96 return True
97 elif inspect.isfunction(object):
97 elif inspect.isfunction(object):
98 return module.__dict__ is object.func_globals
98 return module.__dict__ is object.__globals__
99 elif inspect.isbuiltin(object):
99 elif inspect.isbuiltin(object):
100 return module.__name__ == object.__module__
100 return module.__name__ == object.__module__
101 elif inspect.isclass(object):
101 elif inspect.isclass(object):
@@ -36,8 +36,8 b' def getargspec(obj):'
36 func_obj = obj.im_func
36 func_obj = obj.im_func
37 else:
37 else:
38 raise TypeError('arg is not a Python function')
38 raise TypeError('arg is not a Python function')
39 args, varargs, varkw = inspect.getargs(func_obj.func_code)
39 args, varargs, varkw = inspect.getargs(func_obj.__code__)
40 return args, varargs, varkw, func_obj.func_defaults
40 return args, varargs, varkw, func_obj.__defaults__
41
41
42 #-----------------------------------------------------------------------------
42 #-----------------------------------------------------------------------------
43 # Testing functions
43 # Testing functions
@@ -105,9 +105,9 b' class CannedFunction(CannedObject):'
105
105
106 def __init__(self, f):
106 def __init__(self, f):
107 self._check_type(f)
107 self._check_type(f)
108 self.code = f.func_code
108 self.code = f.__code__
109 if f.func_defaults:
109 if f.__defaults__:
110 self.defaults = [ can(fd) for fd in f.func_defaults ]
110 self.defaults = [ can(fd) for fd in f.__defaults__ ]
111 else:
111 else:
112 self.defaults = None
112 self.defaults = None
113 self.module = f.__module__ or '__main__'
113 self.module = f.__module__ or '__main__'
General Comments 0
You need to be logged in to leave comments. Login now