From e0fc2386083aed55b44d4c50661fb53bd4170a3f 2023-01-21 18:03:39 From: nfgf Date: 2023-01-21 18:03:39 Subject: [PATCH] Documentation update --- diff --git a/IPython/core/magic.py b/IPython/core/magic.py index 95653dc..4f9e4e5 100644 --- a/IPython/core/magic.py +++ b/IPython/core/magic.py @@ -280,7 +280,7 @@ def no_var_expand(magic_func): def output_can_be_silenced(magic_func): """Mark a magic function so its output may be silenced. - The output is silenced if the Python expression used as a parameter of + The output is silenced if the Python code used as a parameter of the magic ends in a semicolon, not counting a Python comment that can follow it. """ diff --git a/docs/source/config/custommagics.rst b/docs/source/config/custommagics.rst index 99d4068..0a37b85 100644 --- a/docs/source/config/custommagics.rst +++ b/docs/source/config/custommagics.rst @@ -139,13 +139,26 @@ Accessing user namespace and local scope ======================================== When creating line magics, you may need to access surrounding scope to get user -variables (e.g when called inside functions). IPython provide the +variables (e.g when called inside functions). IPython provides the ``@needs_local_scope`` decorator that can be imported from ``IPython.core.magics``. When decorated with ``@needs_local_scope`` a magic will be passed ``local_ns`` as an argument. As a convenience ``@needs_local_scope`` can also be applied to cell magics even if cell magics cannot appear at local scope context. +Silencing the magic output +========================== + +Sometimes it may be useful to define a magic that can be silenced the same way +that non-magic expressions can, i.e., by appending a semicolon at the end of the Python +code to be executed. That can be achieved by decorating the magic function with +the decorator ``@output_can_be_silenced`` that can be imported from +``IPython.core.magics``. When this decorator is used, IPython will parse the Python +code used by the magic and, if the last token is a ``;``, the output created by the +magic will not show up on the screen. If you want to see an example of this decorator +in action, take a look on the ``time`` magic defined in +``IPython.core.magics.execution.py``. + Complete Example ================