Skip to content

Commit

Permalink
Merge pull request numpy#3023 from charris/2to3-except
Browse files Browse the repository at this point in the history
2to3: Use modern exception syntax.
  • Loading branch information
seberg committed Feb 27, 2013
2 parents 6de7a4b + 705bf92 commit a369522
Show file tree
Hide file tree
Showing 26 changed files with 55 additions and 55 deletions.
6 changes: 3 additions & 3 deletions numpy/_import_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _init_info_modules(self, packages=None):
try:
exec 'import %s.info as info' % (package_name)
info_modules[package_name] = info
except ImportError, msg:
except ImportError as msg:
self.warn('No scipy-style subpackage %r found in %s. '\
'Ignoring: %s'\
% (package_name,':'.join(self.parent_path), msg))
Expand All @@ -87,7 +87,7 @@ def _init_info_modules(self, packages=None):
open(info_file,filedescriptor[1]),
info_file,
filedescriptor)
except Exception,msg:
except Exception as msg:
self.error(msg)
info_module = None

Expand Down Expand Up @@ -241,7 +241,7 @@ def _execcmd(self,cmdstr):
frame = self.parent_frame
try:
exec (cmdstr, frame.f_globals,frame.f_locals)
except Exception,msg:
except Exception as msg:
self.error('%s -> failed: %s' % (cmdstr,msg))
return True
else:
Expand Down
2 changes: 1 addition & 1 deletion numpy/build_utils/waf.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def do_binary_search(conf, type_name, kw):

try:
conf.run_c_code(**kw)
except conf.errors.ConfigurationError, e:
except conf.errors.ConfigurationError as e:
conf.end_msg("failed !")
if waflib.Logs.verbose > 1:
raise
Expand Down
2 changes: 1 addition & 1 deletion numpy/core/tests/test_half.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
def assert_raises_fpe(strmatch, callable, *args, **kwargs):
try:
callable(*args, **kwargs)
except FloatingPointError, exc:
except FloatingPointError as exc:
assert_(str(exc).find(strmatch) >= 0,
"Did not raise floating point %s error" % strmatch)
else:
Expand Down
2 changes: 1 addition & 1 deletion numpy/core/tests/test_machar.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_underlow(self):
try:
try:
self._run_machar_highprec()
except FloatingPointError, e:
except FloatingPointError as e:
self.fail("Caught %s exception, should not have been raised." % e)
finally:
seterr(**serrstate)
Expand Down
6 changes: 3 additions & 3 deletions numpy/core/tests/test_nditer.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ def test_iter_broadcasting_errors():
[],
[['readonly'], ['readonly'], ['writeonly','no_broadcast']])
assert_(False, 'Should have raised a broadcast error')
except ValueError, e:
except ValueError as e:
msg = str(e)
# The message should contain the shape of the 3rd operand
assert_(msg.find('(2,3)') >= 0,
Expand All @@ -647,7 +647,7 @@ def test_iter_broadcasting_errors():
op_axes=[[0,1], [0,np.newaxis]],
itershape=(4,3))
assert_(False, 'Should have raised a broadcast error')
except ValueError, e:
except ValueError as e:
msg = str(e)
# The message should contain "shape->remappedshape" for each operand
assert_(msg.find('(2,3)->(2,3)') >= 0,
Expand All @@ -664,7 +664,7 @@ def test_iter_broadcasting_errors():
[],
[['writeonly','no_broadcast'], ['readonly']])
assert_(False, 'Should have raised a broadcast error')
except ValueError, e:
except ValueError as e:
msg = str(e)
# The message should contain the shape of the bad operand
assert_(msg.find('(2,1,1)') >= 0,
Expand Down
2 changes: 1 addition & 1 deletion numpy/core/tests/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def assert_raises_fpe(self, fpeerr, flop, x, y):
flop(x, y)
assert_(False,
"Type %s did not raise fpe error '%s'." % (ftype, fpeerr))
except FloatingPointError, exc:
except FloatingPointError as exc:
assert_(str(exc).find(fpeerr) >= 0,
"Type %s raised wrong fpe error '%s'." % (ftype, exc))

Expand Down
2 changes: 1 addition & 1 deletion numpy/core/tests/test_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def test_scalar_format():
try:
assert_equal(fmat.format(val), fmat.format(valtype(val)),
"failed with val %s, type %s" % (val, valtype))
except ValueError, e:
except ValueError as e:
assert_(False,
"format raised exception (fmt='%s', val=%s, type=%s, exc='%s')" %
(fmat, repr(val), repr(valtype), str(e)))
Expand Down
10 changes: 5 additions & 5 deletions numpy/core/tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -1196,10 +1196,10 @@ def test_zeros(self):
good = 'Maximum allowed dimension exceeded'
try:
np.empty(sz)
except ValueError, e:
except ValueError as e:
if not str(e) == good:
self.fail("Got msg '%s', expected '%s'" % (e, good))
except Exception, e:
except Exception as e:
self.fail("Got exception of type %s instead of ValueError" % type(e))

def test_huge_arange(self):
Expand All @@ -1210,10 +1210,10 @@ def test_huge_arange(self):
try:
a = np.arange(sz)
self.assertTrue(np.size == sz)
except ValueError, e:
except ValueError as e:
if not str(e) == good:
self.fail("Got msg '%s', expected '%s'" % (e, good))
except Exception, e:
except Exception as e:
self.fail("Got exception of type %s instead of ValueError" % type(e))

def test_fromiter_bytes(self):
Expand Down Expand Up @@ -1423,7 +1423,7 @@ def test_ticket_1539(self):
c = a.astype(y)
try:
np.dot(b, c)
except TypeError, e:
except TypeError as e:
failures.append((x, y))
if failures:
raise AssertionError("Failures: %r" % failures)
Expand Down
2 changes: 1 addition & 1 deletion numpy/ctypeslib.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def load_library(libname, loader_path):
try:
libpath = os.path.join(libdir, ln)
return ctypes.cdll[libpath]
except OSError, e:
except OSError as e:
exc = e
raise exc

Expand Down
4 changes: 2 additions & 2 deletions numpy/distutils/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def interactive_sys_argv(argv):
import atexit
atexit.register(readline.write_history_file, histfile)
except AttributeError: pass
except Exception, msg:
except Exception as msg:
print msg

task_dict = {'i':show_information,
Expand Down Expand Up @@ -178,7 +178,7 @@ def interactive_sys_argv(argv):
print '-'*68
try:
task_func(argv,readline)
except Exception,msg:
except Exception as msg:
print 'Failed running task %s: %s' % (task,msg)
break
print '-'*68
Expand Down
2 changes: 1 addition & 1 deletion numpy/distutils/system_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,7 @@ def calc_info(self):
## (self.modulename.upper()+'_VERSION_HEX',
## hex(vstr2hex(module.__version__))),
## )
## except Exception,msg:
## except Exception as msg:
## print msg
dict_append(info, define_macros=macros)
include_dirs = self.get_include_dirs()
Expand Down
2 changes: 1 addition & 1 deletion numpy/f2py/capi_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
else:
errmess("\tIgnoring map {'%s':{'%s':'%s'}}: '%s' must be in %s\n"%(k,k1,d[k][k1],d[k][k1],c2py_map.keys()))
outmess('Succesfully applied user defined changes from .f2py_f2cmap\n')
except Exception, msg:
except Exception as msg:
errmess('Failed to apply user defined changes from .f2py_f2cmap: %s. Skipping.\n' % (msg))
cformat_map={'double':'%g',
'float':'%g',
Expand Down
8 changes: 4 additions & 4 deletions numpy/f2py/crackfortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ def analyzeline(m,case,line):
replace(',','+1j*(')
try:
v = eval(initexpr,{},params)
except (SyntaxError,NameError,TypeError),msg:
except (SyntaxError,NameError,TypeError) as msg:
errmess('analyzeline: Failed to evaluate %r. Ignoring: %s\n'\
% (initexpr, msg))
continue
Expand Down Expand Up @@ -2034,7 +2034,7 @@ def get_parameters(vars, global_params={}):
l = markoutercomma(v[1:-1]).split('@,@')
try:
params[n] = eval(v,g_params,params)
except Exception,msg:
except Exception as msg:
params[n] = v
#print params
outmess('get_parameters: got "%s" on %s\n' % (msg,`v`))
Expand Down Expand Up @@ -2062,7 +2062,7 @@ def _eval_scalar(value,params):
value = str(eval(value,{},params))
except (NameError, SyntaxError):
return value
except Exception,msg:
except Exception as msg:
errmess('"%s" in evaluating %r '\
'(available names: %s)\n' \
% (msg,value,params.keys()))
Expand Down Expand Up @@ -2805,7 +2805,7 @@ def crack2fortran(block):
try:
open(l).close()
files.append(l)
except IOError,detail:
except IOError as detail:
errmess('IOError: %s\n'%str(detail))
else:
funcs.append(l)
Expand Down
18 changes: 9 additions & 9 deletions numpy/f2py/diagnose.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ def run():
try:
print 'Found new numpy version %r in %s' % \
(numpy.__version__, numpy.__file__)
except Exception,msg:
except Exception as msg:
print 'error:', msg
print '------'

if has_f2py2e:
try:
print 'Found f2py2e version %r in %s' % \
(f2py2e.__version__.version,f2py2e.__file__)
except Exception,msg:
except Exception as msg:
print 'error:',msg
print '------'

Expand All @@ -77,7 +77,7 @@ def run():
numpy_distutils.numpy_distutils_version.numpy_distutils_version,
numpy_distutils.__file__)
print '------'
except Exception,msg:
except Exception as msg:
print 'error:',msg
print '------'
try:
Expand All @@ -91,10 +91,10 @@ def run():
for compiler_class in build_flib.all_compilers:
compiler_class(verbose=1).is_available()
print '------'
except Exception,msg:
except Exception as msg:
print 'error:',msg
print '------'
except Exception,msg:
except Exception as msg:
print 'error:',msg,'(ignore it, build_flib is obsolute for numpy.distutils 0.2.2 and up)'
print '------'
try:
Expand All @@ -110,10 +110,10 @@ def run():
print 'Checking availability of supported Fortran compilers:'
fcompiler.show_fcompilers()
print '------'
except Exception,msg:
except Exception as msg:
print 'error:',msg
print '------'
except Exception,msg:
except Exception as msg:
print 'error:',msg
print '------'
try:
Expand All @@ -128,7 +128,7 @@ def run():
from numpy_distutils.command.cpuinfo import cpuinfo
print 'ok'
print '------'
except Exception,msg:
except Exception as msg:
print 'error:',msg,'(ignore it)'
print 'Importing numpy_distutils.cpuinfo ...',
from numpy_distutils.cpuinfo import cpuinfo
Expand All @@ -140,7 +140,7 @@ def run():
if name[0]=='_' and name[1]!='_' and getattr(cpu,name[1:])():
print name[1:],
print '------'
except Exception,msg:
except Exception as msg:
print 'error:',msg
print '------'
os.chdir(_path)
Expand Down
2 changes: 1 addition & 1 deletion numpy/f2py/f2py2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def scaninputline(inputline):
try:
open(l).close()
files.append(l)
except IOError,detail:
except IOError as detail:
errmess('IOError: %s. Skipping file "%s".\n'%(str(detail),l))
elif f==-1: skipfuncs.append(l)
elif f==0: onlyfuncs.append(l)
Expand Down
12 changes: 6 additions & 6 deletions numpy/f2py/tests/test_array_from_pyobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def test_inout_2seq(self):

try:
a = self.array([2],intent.in_.inout,self.num2seq)
except TypeError,msg:
except TypeError as msg:
if not str(msg).startswith('failed to initialize intent(inout|inplace|cache) array'):
raise
else:
Expand All @@ -313,7 +313,7 @@ def test_f_inout_23seq(self):
shape = (len(self.num23seq),len(self.num23seq[0]))
try:
a = self.array(shape,intent.in_.inout,obj)
except ValueError,msg:
except ValueError as msg:
if not str(msg).startswith('failed to initialize intent(inout) array'):
raise
else:
Expand Down Expand Up @@ -398,7 +398,7 @@ def test_in_cache_from_2casttype(self):

try:
a = self.array(shape,intent.in_.cache,obj[::-1])
except ValueError,msg:
except ValueError as msg:
if not str(msg).startswith('failed to initialize intent(cache) array'):
raise
else:
Expand All @@ -411,7 +411,7 @@ def test_in_cache_from_2casttype_failure(self):
shape = (len(self.num2seq),)
try:
a = self.array(shape,intent.in_.cache,obj)
except ValueError,msg:
except ValueError as msg:
if not str(msg).startswith('failed to initialize intent(cache) array'):
raise
else:
Expand All @@ -429,7 +429,7 @@ def test_cache_hidden(self):
shape = (-1,3)
try:
a = self.array(shape,intent.cache.hide,None)
except ValueError,msg:
except ValueError as msg:
if not str(msg).startswith('failed to create intent(cache|hide)|optional array'):
raise
else:
Expand All @@ -456,7 +456,7 @@ def test_hidden(self):
shape = (-1,3)
try:
a = self.array(shape,intent.hide,None)
except ValueError,msg:
except ValueError as msg:
if not str(msg).startswith('failed to create intent(cache|hide)|optional array'):
raise
else:
Expand Down
2 changes: 1 addition & 1 deletion numpy/f2py/tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def wrapper(*a, **kw):
if key not in memo:
try:
memo[key] = func(*a, **kw)
except Exception, e:
except Exception as e:
memo[key] = e
raise
ret = memo[key]
Expand Down
4 changes: 2 additions & 2 deletions numpy/lib/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def read_array_header_1_0(fp):
# "descr" : dtype.descr
try:
d = safe_eval(header)
except SyntaxError, e:
except SyntaxError as e:
msg = "Cannot parse header: %r\nException: %r"
raise ValueError(msg % (header, e))
if not isinstance(d, dict):
Expand All @@ -356,7 +356,7 @@ def read_array_header_1_0(fp):
raise ValueError(msg % (d['fortran_order'],))
try:
dtype = numpy.dtype(d['descr'])
except TypeError, e:
except TypeError as e:
msg = "descr is not a valid dtype descriptor: %r"
raise ValueError(msg % (d['descr'],))

Expand Down
2 changes: 1 addition & 1 deletion numpy/lib/tests/test__datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_InvalidHTTP(self):
self.assertRaises(IOError, self.ds.open, url)
try:
self.ds.open(url)
except IOError, e:
except IOError as e:
# Regression test for bug fixed in r4342.
assert_(e.errno is None)

Expand Down
Loading

0 comments on commit a369522

Please sign in to comment.