MCPcopy Index your code
hub / github.com/ipython/ipython / magic_deco

Function magic_deco

IPython/core/magic.py:203–222  ·  view source on GitHub ↗
(arg: _F | str)

Source from the content-addressed store, hash-verified

201 # This is a closure to capture the magic_kind. We could also use a class,
202 # but it's overkill for just that one bit of state.
203 def magic_deco(arg: _F | str) -> _F | Callable[[_F], _F]:
204 retval: _F | Callable[[_F], _F]
205 if callable(arg):
206 # "Naked" decorator call (just @foo, no args)
207 func = arg
208 name = func.__name__
209 retval = arg
210 record_magic(magics, magic_kind, name, name)
211 elif isinstance(arg, str):
212 # Decorator called with arguments (@foo('bar'))
213 name = arg
214
215 def mark(func: _F, *a: Any, **kw: Any) -> _F:
216 record_magic(magics, magic_kind, name, func.__name__)
217 return func
218
219 retval = mark
220 else:
221 raise TypeError("Decorator can only be called with string or function")
222 return retval
223
224 # Ensure the resulting decorator has a usable docstring
225 magic_deco.__doc__ = _docstring_template.format("method", magic_kind)

Callers

nothing calls this directly

Calls 4

record_magicFunction · 0.85
getMethod · 0.80
get_ipythonFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…