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

Function magics_class

IPython/core/magic.py:86–109  ·  view source on GitHub ↗

Class decorator for all subclasses of the main Magics class. 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

(cls)

Source from the content-addressed store, hash-verified

84#-----------------------------------------------------------------------------
85
86def magics_class(cls):
87 """Class decorator for all subclasses of the main Magics class.
88
89 Any class that subclasses Magics *must* also apply this decorator, to
90 ensure that all the methods that have been decorated as line/cell magics
91 get correctly registered in the class instance. This is necessary because
92 when method decorators run, the class does not exist yet, so they
93 temporarily store their information into a module global. Application of
94 this class decorator copies that global data to the class instance and
95 clears the global.
96
97 Obviously, this mechanism is not thread-safe, which means that the
98 *creation* of subclasses of Magic should only be done in a single-thread
99 context. Instantiation of the classes has no restrictions. Given that
100 these classes are typically created at IPython startup time and before user
101 application code becomes active, in practice this should not pose any
102 problems.
103 """
104 cls.registered = True
105 cls.magics = dict(line = magics['line'],
106 cell = magics['cell'])
107 magics['line'] = {}
108 magics['cell'] = {}
109 return cls
110
111
112def record_magic(dct, magic_kind, magic_name, func):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected