MCPcopy Create free account
hub / github.com/ipython/ipython / magic_deco

Function magic_deco

IPython/core/magic.py:186–205  ·  view source on GitHub ↗
(arg)

Source from the content-addressed store, hash-verified

184 # This is a closure to capture the magic_kind. We could also use a class,
185 # but it's overkill for just that one bit of state.
186 def magic_deco(arg):
187 call = lambda f, *a, **k: f(*a, **k)
188
189 if callable(arg):
190 # "Naked" decorator call (just @foo, no args)
191 func = arg
192 name = func.__name__
193 retval = decorator(call, func)
194 record_magic(magics, magic_kind, name, name)
195 elif isinstance(arg, str):
196 # Decorator called with arguments (@foo('bar'))
197 name = arg
198 def mark(func, *a, **kw):
199 record_magic(magics, magic_kind, name, func.__name__)
200 return decorator(call, func)
201 retval = mark
202 else:
203 raise TypeError("Decorator can only be called with "
204 "string or function")
205 return retval
206
207 # Ensure the resulting decorator has a usable docstring
208 magic_deco.__doc__ = _docstring_template.format('method', magic_kind)

Callers

nothing calls this directly

Calls 4

record_magicFunction · 0.85
get_ipythonFunction · 0.70
fFunction · 0.50

Tested by

no test coverage detected