Permalink
Browse files

STY: Fix up some remaining old-style exceptions.

I think that is the end of it.
  • Loading branch information...
1 parent b2793ea commit fd2630366581049af6c9acc4b41315363b47b55a @charris charris committed Apr 5, 2011
@@ -1,5 +1,5 @@
#-*- coding: latin-1 -*-
-"""
+"""
Date/Time string parsing module.
This code is a slightly modified version of Parser.py found in mx.DateTime
@@ -540,8 +540,8 @@ def _parse_date(text):
try:
month = litmonthtable[litmonth]
except KeyError:
- raise ValueError,\
- 'wrong month name: "%s"' % litmonth
+ raise ValueError(
+ 'wrong month name: "%s"' % litmonth)
elif month:
month = int(month)
else:
@@ -726,8 +726,8 @@ def datetime_from_string(text):
return dt.datetime(year,month,day,hour,minute,second, microsecond) - \
dt.timedelta(minutes=offset)
except ValueError, why:
- raise RangeError,\
- 'Failed to parse "%s": %s' % (origtext, why)
+ raise RangeError(
+ 'Failed to parse "%s": %s' % (origtext, why))
def date_from_string(text):
@@ -745,8 +745,8 @@ def date_from_string(text):
try:
return dt.datetime(year,month,day)
except ValueError, why:
- raise RangeError,\
- 'Failed to parse "%s": %s' % (text, why)
+ raise RangeError(
+ 'Failed to parse "%s": %s' % (text, why))
def validateDateTimeString(text):
View
@@ -140,7 +140,7 @@ def _init(self, dtype):
fmt = '%12.5e'
precname = 'half'
else:
- raise ValueError, repr(dtype)
+ raise ValueError(repr(dtype))
machar = MachAr(lambda v:array([v], dtype),
lambda v:_frz(v.astype(itype))[0],
View
@@ -128,7 +128,7 @@ def _do_init(self, float_conv, int_conv, float_to_float, float_to_str, title):
if any(temp1 - one != zero):
break
else:
- raise RuntimeError, msg % (_, one.dtype)
+ raise RuntimeError(msg % (_, one.dtype))
b = one
for _ in xrange(max_iterN):
b = b + b
@@ -137,7 +137,7 @@ def _do_init(self, float_conv, int_conv, float_to_float, float_to_str, title):
if any(itemp != 0):
break
else:
- raise RuntimeError, msg % (_, one.dtype)
+ raise RuntimeError(msg % (_, one.dtype))
ibeta = itemp
beta = float_conv(ibeta)
@@ -152,7 +152,7 @@ def _do_init(self, float_conv, int_conv, float_to_float, float_to_str, title):
if any(temp1 - one != zero):
break
else:
- raise RuntimeError, msg % (_, one.dtype)
+ raise RuntimeError(msg % (_, one.dtype))
betah = beta / two
a = one
@@ -163,7 +163,7 @@ def _do_init(self, float_conv, int_conv, float_to_float, float_to_str, title):
if any(temp1 - one != zero):
break
else:
- raise RuntimeError, msg % (_, one.dtype)
+ raise RuntimeError(msg % (_, one.dtype))
temp = a + betah
irnd = 0
if any(temp-a != zero):
@@ -191,7 +191,7 @@ def _do_init(self, float_conv, int_conv, float_to_float, float_to_str, title):
raise RuntimeError("could not determine machine tolerance "
"for 'negep', locals() -> %s" % (locals()))
else:
- raise RuntimeError, msg % (_, one.dtype)
+ raise RuntimeError(msg % (_, one.dtype))
negep = -negep
epsneg = a
@@ -206,7 +206,7 @@ def _do_init(self, float_conv, int_conv, float_to_float, float_to_str, title):
a = a * beta
machep = machep + 1
else:
- raise RuntimeError, msg % (_, one.dtype)
+ raise RuntimeError(msg % (_, one.dtype))
eps = a
# Determine ngrd
@@ -234,7 +234,7 @@ def _do_init(self, float_conv, int_conv, float_to_float, float_to_str, title):
i = i + 1
k = k + k
else:
- raise RuntimeError, msg % (_, one.dtype)
+ raise RuntimeError(msg % (_, one.dtype))
if ibeta != 10:
iexp = i + 1
mx = k + k
@@ -262,7 +262,7 @@ def _do_init(self, float_conv, int_conv, float_to_float, float_to_str, title):
else:
break
else:
- raise RuntimeError, msg % (_, one.dtype)
+ raise RuntimeError(msg % (_, one.dtype))
minexp = -k
# Determine maxexp, xmax
View
@@ -1109,9 +1109,9 @@ def rollaxis(a, axis, start=0):
start += n
msg = 'rollaxis: %s (%d) must be >=0 and < %d'
if not (0 <= axis < n):
- raise ValueError, msg % ('axis', axis, n)
+ raise ValueError(msg % ('axis', axis, n))
if not (0 <= start < n+1):
- raise ValueError, msg % ('start', start, n+1)
+ raise ValueError(msg % ('start', start, n+1))
if (axis < start): # it's been removed
start -= 1
if axis==start:
@@ -355,7 +355,7 @@ def _build_import_library_x86():
log.warn('Failed to build import library for gcc. Linking will fail.')
#if not success:
# msg = "Couldn't find import library, and failed to build it."
- # raise DistutilsPlatformError, msg
+ # raise DistutilsPlatformError(msg)
return
#=====================================
View
@@ -633,7 +633,7 @@ def listdir(self):
"""
if self._isurl(self._baseurl):
- raise NotImplementedError, \
- "Directory listing of URLs, not supported yet."
+ raise NotImplementedError(
+ "Directory listing of URLs, not supported yet.")
else:
return os.listdir(self._baseurl)
View
@@ -113,7 +113,7 @@ def __getattribute__(self, key):
try:
return object.__getattribute__(self, '_obj')[key]
except KeyError:
- raise AttributeError, key
+ raise AttributeError(key)
def zipfile_factory(*args, **kwargs):
import zipfile
@@ -353,8 +353,8 @@ def load(file, mmap_mode=None):
try:
return _cload(fid)
except:
- raise IOError, \
- "Failed to interpret file %s as a pickle" % repr(file)
+ raise IOError(
+ "Failed to interpret file %s as a pickle" % repr(file))
finally:
if own_fid:
fid.close()
View
@@ -306,8 +306,8 @@ def polyint(p, m=1, k=None):
if len(k) == 1 and m > 1:
k = k[0]*NX.ones(m, float)
if len(k) < m:
- raise ValueError, \
- "k must be a scalar or a rank-1 array of length 1 or >m."
+ raise ValueError(
+ "k must be a scalar or a rank-1 array of length 1 or >m.")
truepoly = isinstance(p, poly1d)
p = NX.asarray(p)
View
@@ -1798,7 +1798,7 @@ def masked_where(condition, a, copy=True):
(cshape, ashape) = (cond.shape, a.shape)
if cshape and cshape != ashape:
- raise IndexError("Inconsistant shape between the condition and the input"\
+ raise IndexError("Inconsistant shape between the condition and the input"
" (got %s and %s)" % (cshape, ashape))
if hasattr(a, '_mask'):
cond = mask_or(cond, a._mask)
@@ -2703,7 +2703,7 @@ def __new__(cls, data=None, mask=nomask, dtype=None, copy=False,
else:
msg = "Mask and data not compatible: data size is %i, " + \
"mask size is %i."
- raise MaskError, msg % (nd, nm)
+ raise MaskError(msg % (nd, nm))
copy = True
# Set the mask to the new value
if _data._mask is nomask:
@@ -2930,7 +2930,7 @@ def __getitem__(self, indx):
# This test is useful, but we should keep things light...
# if getmask(indx) is not nomask:
# msg = "Masked arrays must be filled before they can be used as indices!"
-# raise IndexError, msg
+# raise IndexError(msg)
_data = ndarray.view(self, ndarray)
dout = ndarray.__getitem__(_data, indx)
# We could directly use ndarray.__getitem__ on self...
@@ -2980,7 +2980,7 @@ def __setitem__(self, indx, value):
# This test is useful, but we should keep things light...
# if getmask(indx) is not nomask:
# msg = "Masked arrays must be filled before they can be used as indices!"
-# raise IndexError, msg
+# raise IndexError(msg)
_data = ndarray.view(self, ndarray.__getattribute__(self, '_baseclass'))
_mask = ndarray.__getattribute__(self, '_mask')
if isinstance(indx, basestring):
@@ -3779,7 +3779,7 @@ def __ipow__(self, other):
def __float__(self):
"Convert to float."
if self.size > 1:
- raise TypeError("Only length-1 arrays can be converted "\
+ raise TypeError("Only length-1 arrays can be converted "
"to Python scalars")
elif self._mask:
warnings.warn("Warning: converting a masked element to nan.")
@@ -3789,7 +3789,7 @@ def __float__(self):
def __int__(self):
"Convert to int."
if self.size > 1:
- raise TypeError("Only length-1 arrays can be converted "\
+ raise TypeError("Only length-1 arrays can be converted "
"to Python scalars")
elif self._mask:
raise MaskError('Cannot convert masked element to a Python int.')
View
@@ -614,10 +614,10 @@ def __array__ (self, t=None, context=None):
"numeric because data\n is masked in one or "\
"more locations.");
return self._data
- #raise MAError, \
+ #raise MAError(
# """Cannot automatically convert masked array to numeric because data
# is masked in one or more locations.
- # """
+ # """)
else:
func, args, i = context
fills = ufunc_fills.get(func)
@@ -33,7 +33,8 @@ def _lookup(table, key, required_bits):
for bits, typecode in lst:
if bits >= required_bits:
return typecode
- raise PrecisionError, key+" of "+str(required_bits)+" bits not available on this system"
+ raise PrecisionError(key + " of " + str(required_bits) +
+ " bits not available on this system")
Character = 'c'
@@ -19,10 +19,10 @@ def seed(x=0, y=0):
mt.seed((x,y))
def get_seed():
- raise NotImplementedError, \
- "If you want to save the state of the random number generator.\n"\
- "Then you should use obj = numpy.random.get_state() followed by.\n"\
- "numpy.random.set_state(obj)."
+ raise NotImplementedError(
+ "If you want to save the state of the random number generator.\n"
+ "Then you should use obj = numpy.random.get_state() followed by.\n"
+ "numpy.random.set_state(obj).")
def random(shape=[]):
"random(n) or random([n, m, ...]) returns array of random numbers"
@@ -9,7 +9,7 @@
class NullTester(object):
def test(self, labels=None, *args, **kwargs):
- raise ImportError, \
- 'Need nose >=0.10 for tests - see %s' % \
- 'http://somethingaboutorange.com/mrl/projects/nose'
+ raise ImportError(
+ 'Need nose >=0.10 for tests - see %s' %
+ 'http://somethingaboutorange.com/mrl/projects/nose')
bench = test

0 comments on commit fd26303

Please sign in to comment.