This is a development version (latest) and may be unstable. Go to latest (9.13.0)
{ } Raw JSON

bundles / IPython latest / IPython / core / magic / magics_class

function

IPython.core.magic:magics_class

source: /IPython/core/magic.py :100

Signature

def   magics_class ( cls : _T )  →  _T

Summary

Class decorator for all subclasses of the main Magics class.

Extended Summary

Any class that subclasses Magics must also apply this decorator, to ensure that all the methods that have been decorated as line/cell magics get correctly registered in the class instance. This is necessary because when method decorators run, the class does not exist yet, so they temporarily store their information into a module global. Application of this class decorator copies that global data to the class instance and clears the global.

Obviously, this mechanism is not thread-safe, which means that the creation of subclasses of Magic should only be done in a single-thread context. Instantiation of the classes has no restrictions. Given that these classes are typically created at IPython startup time and before user application code becomes active, in practice this should not pose any problems.

Aliases

  • IPython.core.magic.magics_class