summaryrefslogtreecommitdiffstats
path: root/contrib/python/ipython/py3/IPython/extensions/storemagic.py
diff options
context:
space:
mode:
authorrobot-contrib <[email protected]>2022-05-18 00:43:36 +0300
committerrobot-contrib <[email protected]>2022-05-18 00:43:36 +0300
commit9e5f436a8b2a27bcc7802e443ea3ef3e41a82a75 (patch)
tree78b522cab9f76336e62064d4d8ff7c897659b20e /contrib/python/ipython/py3/IPython/extensions/storemagic.py
parent8113a823ffca6451bb5ff8f0334560885a939a24 (diff)
Update contrib/python/ipython/py3 to 8.3.0
ref:e84342d4d30476f9148137f37fd0c6405fd36f55
Diffstat (limited to 'contrib/python/ipython/py3/IPython/extensions/storemagic.py')
-rw-r--r--contrib/python/ipython/py3/IPython/extensions/storemagic.py25
1 files changed, 14 insertions, 11 deletions
diff --git a/contrib/python/ipython/py3/IPython/extensions/storemagic.py b/contrib/python/ipython/py3/IPython/extensions/storemagic.py
index 51b79ad314e..d9d00f14b9a 100644
--- a/contrib/python/ipython/py3/IPython/extensions/storemagic.py
+++ b/contrib/python/ipython/py3/IPython/extensions/storemagic.py
@@ -17,6 +17,7 @@ import inspect, os, sys, textwrap
from IPython.core.error import UsageError
from IPython.core.magic import Magics, magics_class, line_magic
+from IPython.testing.skipdoctest import skip_doctest
from traitlets import Bool
@@ -74,6 +75,7 @@ class StoreMagics(Magics):
if self.autorestore:
restore_data(self.shell)
+ @skip_doctest
@line_magic
def store(self, parameter_s=''):
"""Lightweight persistence for python variables.
@@ -82,6 +84,7 @@ class StoreMagics(Magics):
In [1]: l = ['hello',10,'world']
In [2]: %store l
+ Stored 'l' (list)
In [3]: exit
(IPython session is closed and started again...)
@@ -126,13 +129,13 @@ class StoreMagics(Magics):
if 'd' in opts:
try:
todel = args[0]
- except IndexError:
- raise UsageError('You must provide the variable to forget')
+ except IndexError as e:
+ raise UsageError('You must provide the variable to forget') from e
else:
try:
del db['autorestore/' + todel]
- except:
- raise UsageError("Can't delete variable '%s'" % todel)
+ except BaseException as e:
+ raise UsageError("Can't delete variable '%s'" % todel) from e
# reset
elif 'z' in opts:
for k in db.keys('autorestore/*'):
@@ -173,12 +176,12 @@ class StoreMagics(Magics):
# default action - store the variable
else:
# %store foo >file.txt or >>file.txt
- if len(args) > 1 and args[1].startswith('>'):
- fnam = os.path.expanduser(args[1].lstrip('>').lstrip())
- if args[1].startswith('>>'):
- fil = open(fnam, 'a')
+ if len(args) > 1 and args[1].startswith(">"):
+ fnam = os.path.expanduser(args[1].lstrip(">").lstrip())
+ if args[1].startswith(">>"):
+ fil = open(fnam, "a", encoding="utf-8")
else:
- fil = open(fnam, 'w')
+ fil = open(fnam, "w", encoding="utf-8")
with fil:
obj = ip.ev(args[0])
print("Writing '%s' (%s) to file '%s'." % (args[0],
@@ -203,8 +206,8 @@ class StoreMagics(Magics):
name = arg
try:
cmd = ip.alias_manager.retrieve_alias(name)
- except ValueError:
- raise UsageError("Unknown variable '%s'" % name)
+ except ValueError as e:
+ raise UsageError("Unknown variable '%s'" % name) from e
staliases = db.get('stored_aliases',{})
staliases[name] = cmd