From eca010b4873d5f3880871e794ba36f55b090bf28 2024-11-04 18:07:37 From: M Bussonnier Date: 2024-11-04 18:07:37 Subject: [PATCH] Use non-deprecated run_line_magic function --- diff --git a/IPython/core/magics/basic.py b/IPython/core/magics/basic.py index f707bcc..11b5693 100644 --- a/IPython/core/magics/basic.py +++ b/IPython/core/magics/basic.py @@ -461,7 +461,7 @@ Currently the magic system has the following functions:""", ptformatter.pprint = False disp_formatter.active_types = ['text/plain'] - shell.magic('xmode Plain') + shell.run_line_magic("xmode", "Plain") else: # turn off shell.separate_in = dstore.rc_separate_in diff --git a/IPython/core/magics/logging.py b/IPython/core/magics/logging.py index b6b8d8a..81b1675 100644 --- a/IPython/core/magics/logging.py +++ b/IPython/core/magics/logging.py @@ -83,14 +83,14 @@ class LoggingMagics(Magics): log 'raw' input. Normally, IPython's logs contain the processed input, so that user lines are logged in their final form, converted into valid Python. For example, %Exit is logged as - _ip.magic("Exit"). If the -r flag is given, all input is logged + _ip.run_line_magic("Exit"). If the -r flag is given, all input is logged exactly as typed, with no transformations applied. -t put timestamps before each input line logged (these are put in comments). - -q + -q suppress output of logstate message when logging is invoked """ diff --git a/IPython/extensions/tests/test_storemagic.py b/IPython/extensions/tests/test_storemagic.py index 3ac306b..66122ab 100644 --- a/IPython/extensions/tests/test_storemagic.py +++ b/IPython/extensions/tests/test_storemagic.py @@ -5,22 +5,27 @@ from traitlets.config.loader import Config def setup_module(): - ip.magic('load_ext storemagic') + ip.run_line_magic("load_ext", "storemagic") + def test_store_restore(): - assert 'bar' not in ip.user_ns, "Error: some other test leaked `bar` in user_ns" - assert 'foo' not in ip.user_ns, "Error: some other test leaked `foo` in user_ns" - assert 'foobar' not in ip.user_ns, "Error: some other test leaked `foobar` in user_ns" - assert 'foobaz' not in ip.user_ns, "Error: some other test leaked `foobaz` in user_ns" - ip.user_ns['foo'] = 78 - ip.magic('alias bar echo "hello"') - ip.user_ns['foobar'] = 79 - ip.user_ns['foobaz'] = '80' + assert "bar" not in ip.user_ns, "Error: some other test leaked `bar` in user_ns" + assert "foo" not in ip.user_ns, "Error: some other test leaked `foo` in user_ns" + assert ( + "foobar" not in ip.user_ns + ), "Error: some other test leaked `foobar` in user_ns" + assert ( + "foobaz" not in ip.user_ns + ), "Error: some other test leaked `foobaz` in user_ns" + ip.user_ns["foo"] = 78 + ip.run_line_magic("alias", 'bar echo "hello"') + ip.user_ns["foobar"] = 79 + ip.user_ns["foobaz"] = "80" tmpd = tempfile.mkdtemp() - ip.magic('cd ' + tmpd) - ip.magic('store foo') - ip.magic('store bar') - ip.magic('store foobar foobaz') + ip.run_line_magic("cd", tmpd) + ip.run_line_magic("store", "foo") + ip.run_line_magic("store", "bar") + ip.run_line_magic("store", "foobar foobaz") # Check storing assert ip.db["autorestore/foo"] == 78 @@ -29,29 +34,29 @@ def test_store_restore(): assert ip.db["autorestore/foobaz"] == "80" # Remove those items - ip.user_ns.pop('foo', None) - ip.user_ns.pop('foobar', None) - ip.user_ns.pop('foobaz', None) - ip.alias_manager.undefine_alias('bar') - ip.magic('cd -') - ip.user_ns['_dh'][:] = [] + ip.user_ns.pop("foo", None) + ip.user_ns.pop("foobar", None) + ip.user_ns.pop("foobaz", None) + ip.alias_manager.undefine_alias("bar") + ip.run_line_magic("cd", "-") + ip.user_ns["_dh"][:] = [] # Check restoring - ip.magic("store -r foo bar foobar foobaz") + ip.run_line_magic("store", "-r foo bar foobar foobaz") assert ip.user_ns["foo"] == 78 assert ip.alias_manager.is_alias("bar") assert ip.user_ns["foobar"] == 79 assert ip.user_ns["foobaz"] == "80" - ip.magic("store -r") # restores _dh too + ip.run_line_magic("store", "-r") # restores _dh too assert any(Path(tmpd).samefile(p) for p in ip.user_ns["_dh"]) os.rmdir(tmpd) def test_autorestore(): - ip.user_ns['foo'] = 95 - ip.magic('store foo') - del ip.user_ns['foo'] + ip.user_ns["foo"] = 95 + ip.run_line_magic("store", "foo") + del ip.user_ns["foo"] c = Config() c.StoreMagics.autorestore = False orig_config = ip.config