typos/better errors

This commit is contained in:
laerus 2016-07-20 21:34:02 +03:00
parent 877a2c9cfb
commit 144fdef511
2 changed files with 7 additions and 3 deletions

View file

@ -462,7 +462,11 @@ def _hist_show(ns=None, hist=None, start_index=None, end_index=None,
if ns:
_commands = []
for s in ns.slices:
s = ensure_slice(s)
try:
s = ensure_slice(s)
except (ValueError, TypeError):
print('{!r} is not a valid slice format'.format(s), file=sys.stderr)
return
if s:
try:
_commands.extend(commands[s])

View file

@ -929,7 +929,7 @@ def SLICE_REG():
return re.compile(r'(?P<start>(?:-\d)?\d*):(?P<end>(?:-\d)?\d*):?(?P<step>(?:-\d)?\d*)')
def ensure_slice(x):
"""Covert a string or int to a slice."""
"""Convert a string or int to a slice."""
if x is None:
return slice(None)
try:
@ -942,7 +942,7 @@ def ensure_slice(x):
groups = (int(i) if i else None for i in m.groups())
s = slice(*groups)
else:
raise ValueError('cannot convert {} to slice'.format(x))
raise ValueError('cannot convert {!r} to slice'.format(x))
except TypeError:
raise TypeError('ensure_slice() argument must be a string or a number not {}'.format(type(x)))
return s