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

Method register_alias

IPython/core/magic.py:447–475  ·  view source on GitHub ↗

Register an alias to a magic function. The alias is an instance of :class:`MagicAlias`, which holds the name and kind of the magic it should call. Binding is done at call time, so if the underlying magic function is changed the alias will call the new function.

(self, alias_name, magic_name, magic_kind='line', magic_params=None)

Source from the content-addressed store, hash-verified

445 record_magic(self.magics, magic_kind, magic_name, func)
446
447 def register_alias(self, alias_name, magic_name, magic_kind='line', magic_params=None):
448 """Register an alias to a magic function.
449
450 The alias is an instance of :class:`MagicAlias`, which holds the
451 name and kind of the magic it should call. Binding is done at
452 call time, so if the underlying magic function is changed the alias
453 will call the new function.
454
455 Parameters
456 ----------
457 alias_name : str
458 The name of the magic to be registered.
459
460 magic_name : str
461 The name of an existing magic.
462
463 magic_kind : str
464 Kind of magic, one of 'line' or 'cell'
465 """
466
467 # `validate_type` is too permissive, as it allows 'line_cell'
468 # which we do not handle.
469 if magic_kind not in magic_kinds:
470 raise ValueError('magic_kind must be one of %s, %s given' %
471 magic_kinds, magic_kind)
472
473 alias = MagicAlias(self.shell, magic_name, magic_kind, magic_params)
474 setattr(self.user_magics, alias_name, alias)
475 record_magic(self.magics, magic_kind, alias_name, alias)
476
477# Key base class that provides the central functionality for magics.
478

Callers 2

init_magicsMethod · 0.80
alias_magicMethod · 0.80

Calls 2

MagicAliasClass · 0.85
record_magicFunction · 0.85

Tested by

no test coverage detected