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

Method register

IPython/core/magic.py:377–411  ·  view source on GitHub ↗

Register one or more instances of Magics. Take one or more classes or instances of classes that subclass the main `core.Magic` class, and register them with IPython to use the magic functions they provide. The registration process will then ensure that any methods

(self, *magic_objects)

Source from the content-addressed store, hash-verified

375 return docs
376
377 def register(self, *magic_objects):
378 """Register one or more instances of Magics.
379
380 Take one or more classes or instances of classes that subclass the main
381 `core.Magic` class, and register them with IPython to use the magic
382 functions they provide. The registration process will then ensure that
383 any methods that have decorated to provide line and/or cell magics will
384 be recognized with the `%x`/`%%x` syntax as a line/cell magic
385 respectively.
386
387 If classes are given, they will be instantiated with the default
388 constructor. If your classes need a custom constructor, you should
389 instanitate them first and pass the instance.
390
391 The provided arguments can be an arbitrary mix of classes and instances.
392
393 Parameters
394 ----------
395 magic_objects : one or more classes or instances
396 """
397 # Start by validating them to ensure they have all had their magic
398 # methods registered at the instance level
399 for m in magic_objects:
400 if not m.registered:
401 raise ValueError("Class of magics %r was constructed without "
402 "the @register_magics class decorator")
403 if isinstance(m, type):
404 # If we're given an uninstantiated class
405 m = m(shell=self.shell)
406
407 # Now that we have an instance, we can register it and update the
408 # table of callables
409 self.registry[m.__class__.__name__] = m
410 for mtype in magic_kinds:
411 self.magics[mtype].update(m.magics[mtype])
412
413 def register_function(self, func, magic_kind='line', magic_name=None):
414 """Expose a standalone function as magic function for IPython.

Callers

nothing calls this directly

Calls 1

updateMethod · 0.45

Tested by

no test coverage detected