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

Method register_alias

IPython/core/magic.py:548–583  ·  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: str,
        magic_name: str,
        magic_kind: _MagicKind = "line",
        magic_params: str | None = None,
    )

Source from the content-addressed store, hash-verified

546 record_magic(self.magics, magic_kind, magic_name, func)
547
548 def register_alias(
549 self,
550 alias_name: str,
551 magic_name: str,
552 magic_kind: _MagicKind = "line",
553 magic_params: str | None = None,
554 ) -> None:
555 """Register an alias to a magic function.
556
557 The alias is an instance of :class:`MagicAlias`, which holds the
558 name and kind of the magic it should call. Binding is done at
559 call time, so if the underlying magic function is changed the alias
560 will call the new function.
561
562 Parameters
563 ----------
564 alias_name : str
565 The name of the magic to be registered.
566 magic_name : str
567 The name of an existing magic.
568 magic_kind : str
569 Kind of magic, one of 'line' or 'cell'
570 """
571
572 # `validate_type` is too permissive, as it allows 'line_cell'
573 # which we do not handle.
574 if magic_kind not in magic_kinds:
575 raise ValueError(
576 "magic_kind must be one of %s, %s given" % magic_kinds, magic_kind
577 )
578
579 assert self.shell is not None
580 assert self.user_magics is not None
581 alias = MagicAlias(self.shell, magic_name, magic_kind, magic_params)
582 setattr(self.user_magics, alias_name, alias)
583 record_magic(self.magics, magic_kind, alias_name, alias)
584
585
586# Key base class that provides the central functionality for magics.

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