diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2013-02-26 20:04:59 -0700 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2013-02-26 20:04:59 -0700 |
commit | 705bf928e1256a06019c75ee945370fbe89cdde7 (patch) | |
tree | 3e1d8ebcef67a93d8d5eeb63db1256406ae5c49f | |
parent | 17774a6d58b889b6b7a25d6af5b66f2148d47f41 (diff) | |
download | numpy-705bf928e1256a06019c75ee945370fbe89cdde7.tar.gz |
2to3: Use modern exception syntax.
Example: except ValueError,msg: -> except ValueError as msg:
26 files changed, 55 insertions, 55 deletions
diff --git a/numpy/_import_tools.py b/numpy/_import_tools.py index c0a901a8d..6223dd57f 100644 --- a/numpy/_import_tools.py +++ b/numpy/_import_tools.py @@ -68,7 +68,7 @@ class PackageLoader(object): 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)) @@ -87,7 +87,7 @@ class PackageLoader(object): open(info_file,filedescriptor[1]), info_file, filedescriptor) - except Exception,msg: + except Exception as msg: self.error(msg) info_module = None @@ -241,7 +241,7 @@ class PackageLoader(object): 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: diff --git a/numpy/build_utils/waf.py b/numpy/build_utils/waf.py index 4ef71327c..e8f63c570 100644 --- a/numpy/build_utils/waf.py +++ b/numpy/build_utils/waf.py @@ -166,7 +166,7 @@ int main () 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 diff --git a/numpy/core/tests/test_half.py b/numpy/core/tests/test_half.py index 31a206e1c..f1cf36b5b 100644 --- a/numpy/core/tests/test_half.py +++ b/numpy/core/tests/test_half.py @@ -9,7 +9,7 @@ from numpy.testing import TestCase, run_module_suite, assert_, assert_equal, \ 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: diff --git a/numpy/core/tests/test_machar.py b/numpy/core/tests/test_machar.py index 4175ceeac..99046ca2a 100644 --- a/numpy/core/tests/test_machar.py +++ b/numpy/core/tests/test_machar.py @@ -21,7 +21,7 @@ class TestMachAr(TestCase): 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) diff --git a/numpy/core/tests/test_nditer.py b/numpy/core/tests/test_nditer.py index 4abe5e2ff..f40ac68a8 100644 --- a/numpy/core/tests/test_nditer.py +++ b/numpy/core/tests/test_nditer.py @@ -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, @@ -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, @@ -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, diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py index b6a9c5157..6b5f86e5a 100644 --- a/numpy/core/tests/test_numeric.py +++ b/numpy/core/tests/test_numeric.py @@ -269,7 +269,7 @@ class TestFloatExceptions(TestCase): 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)) diff --git a/numpy/core/tests/test_print.py b/numpy/core/tests/test_print.py index d40275ef4..aed262ad2 100644 --- a/numpy/core/tests/test_print.py +++ b/numpy/core/tests/test_print.py @@ -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))) diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py index 9a193b3c1..c49c2a17e 100644 --- a/numpy/core/tests/test_regression.py +++ b/numpy/core/tests/test_regression.py @@ -1185,10 +1185,10 @@ class TestRegression(TestCase): 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): @@ -1199,10 +1199,10 @@ class TestRegression(TestCase): 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): @@ -1412,7 +1412,7 @@ class TestRegression(TestCase): 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) diff --git a/numpy/ctypeslib.py b/numpy/ctypeslib.py index c11900947..229a5f0ba 100644 --- a/numpy/ctypeslib.py +++ b/numpy/ctypeslib.py @@ -126,7 +126,7 @@ else: try: libpath = os.path.join(libdir, ln) return ctypes.cdll[libpath] - except OSError, e: + except OSError as e: exc = e raise exc diff --git a/numpy/distutils/interactive.py b/numpy/distutils/interactive.py index e3dba04eb..896a7d91e 100644 --- a/numpy/distutils/interactive.py +++ b/numpy/distutils/interactive.py @@ -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, @@ -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 diff --git a/numpy/distutils/system_info.py b/numpy/distutils/system_info.py index 4dd3d4b6b..38a8b25a5 100644 --- a/numpy/distutils/system_info.py +++ b/numpy/distutils/system_info.py @@ -1667,7 +1667,7 @@ class _numpy_info(system_info): ## (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() diff --git a/numpy/f2py/capi_maps.py b/numpy/f2py/capi_maps.py index dd8277aaf..42d506d74 100644 --- a/numpy/f2py/capi_maps.py +++ b/numpy/f2py/capi_maps.py @@ -192,7 +192,7 @@ if os.path.isfile('.f2py_f2cmap'): 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', diff --git a/numpy/f2py/crackfortran.py b/numpy/f2py/crackfortran.py index 5d664e399..f610548d6 100755 --- a/numpy/f2py/crackfortran.py +++ b/numpy/f2py/crackfortran.py @@ -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 @@ -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`)) @@ -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())) @@ -2805,7 +2805,7 @@ if __name__ == "__main__": try: open(l).close() files.append(l) - except IOError,detail: + except IOError as detail: errmess('IOError: %s\n'%str(detail)) else: funcs.append(l) diff --git a/numpy/f2py/diagnose.py b/numpy/f2py/diagnose.py index 3b517a5c9..e45f9950e 100644 --- a/numpy/f2py/diagnose.py +++ b/numpy/f2py/diagnose.py @@ -54,7 +54,7 @@ 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 '------' @@ -62,7 +62,7 @@ def run(): try: print 'Found f2py2e version %r in %s' % \ (f2py2e.__version__.version,f2py2e.__file__) - except Exception,msg: + except Exception as msg: print 'error:',msg print '------' @@ -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: @@ -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: @@ -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: @@ -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 @@ -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) diff --git a/numpy/f2py/f2py2e.py b/numpy/f2py/f2py2e.py index 4e6d2587f..a5935c51b 100755 --- a/numpy/f2py/f2py2e.py +++ b/numpy/f2py/f2py2e.py @@ -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) diff --git a/numpy/f2py/tests/test_array_from_pyobj.py b/numpy/f2py/tests/test_array_from_pyobj.py index be85a308a..c1b927c1c 100644 --- a/numpy/f2py/tests/test_array_from_pyobj.py +++ b/numpy/f2py/tests/test_array_from_pyobj.py @@ -297,7 +297,7 @@ class _test_shared_memory: 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: @@ -313,7 +313,7 @@ class _test_shared_memory: 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: @@ -398,7 +398,7 @@ class _test_shared_memory: 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: @@ -411,7 +411,7 @@ class _test_shared_memory: 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: @@ -429,7 +429,7 @@ class _test_shared_memory: 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: @@ -456,7 +456,7 @@ class _test_shared_memory: 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: diff --git a/numpy/f2py/tests/util.py b/numpy/f2py/tests/util.py index a5816b96f..627bc0af9 100644 --- a/numpy/f2py/tests/util.py +++ b/numpy/f2py/tests/util.py @@ -71,7 +71,7 @@ def _memoize(func): 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] diff --git a/numpy/lib/format.py b/numpy/lib/format.py index 1e508f3e5..bff582f7d 100644 --- a/numpy/lib/format.py +++ b/numpy/lib/format.py @@ -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): @@ -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'],)) diff --git a/numpy/lib/tests/test__datasource.py b/numpy/lib/tests/test__datasource.py index ed5af516f..3f8697507 100644 --- a/numpy/lib/tests/test__datasource.py +++ b/numpy/lib/tests/test__datasource.py @@ -92,7 +92,7 @@ class TestDataSourceOpen(TestCase): 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) diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index f8caeedb6..b7fa94448 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -151,7 +151,7 @@ class TestSavezLoad(RoundtripTest, TestCase): arr = np.random.randn(500, 500) try: np.savez(tmp, arr=arr) - except OSError, err: + except OSError as err: error_list.append(err) finally: os.remove(tmp) @@ -207,7 +207,7 @@ class TestSavezLoad(RoundtripTest, TestCase): for i in range(1, 1025): try: np.load(tmp)["data"] - except Exception, e: + except Exception as e: raise AssertionError("Failed to load data from a file: %s" % e) finally: os.remove(tmp) diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index dc6c16767..820e6d8f9 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -1154,11 +1154,11 @@ def safe_eval(source): walker = SafeEval() try: ast = compiler.parse(source, mode="eval") - except SyntaxError, err: + except SyntaxError as err: raise try: return walker.visit(ast) - except SyntaxError, err: + except SyntaxError as err: raise #----------------------------------------------------------------------------- diff --git a/numpy/linalg/tests/test_linalg.py b/numpy/linalg/tests/test_linalg.py index 623939863..cfb412882 100644 --- a/numpy/linalg/tests/test_linalg.py +++ b/numpy/linalg/tests/test_linalg.py @@ -63,7 +63,7 @@ class LinalgTestCase(object): try: self.do(a, b) raise AssertionError("%s should fail with empty matrices", self.__name__[5:]) - except linalg.LinAlgError, e: + except linalg.LinAlgError as e: pass def test_nonarray(self): diff --git a/numpy/ma/core.py b/numpy/ma/core.py index dbd619b80..861ca268d 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -110,7 +110,7 @@ def get_object_signature(obj): """ try: sig = formatargspec(*getargspec(obj)) - except TypeError, errmsg: + except TypeError as errmsg: sig = '' # msg = "Unable to retrieve the signature of %s '%s'\n"\ # "(Initial error message: %s)" diff --git a/numpy/testing/numpytest.py b/numpy/testing/numpytest.py index 683df7a01..f72626cf0 100644 --- a/numpy/testing/numpytest.py +++ b/numpy/testing/numpytest.py @@ -43,7 +43,7 @@ def importall(package): name = package_name+'.'+subpackage_name try: exec 'import %s as m' % (name) - except Exception, msg: + except Exception as msg: print 'Failed importing %s: %s' %(name, msg) continue importall(m) diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py index 16ed0f803..2d3965594 100644 --- a/numpy/testing/utils.py +++ b/numpy/testing/utils.py @@ -643,7 +643,7 @@ def assert_array_compare(comparison, x, y, err_msg='', verbose=True, names=('x', 'y')) if not cond : raise AssertionError(msg) - except ValueError, e: + except ValueError as e: import traceback efmt = traceback.format_exc() header = 'error during assertion:\n\n%s\n\n%s' % (efmt, header) diff --git a/numpy/tests/test_ctypeslib.py b/numpy/tests/test_ctypeslib.py index ac351191a..7bb93dd9b 100644 --- a/numpy/tests/test_ctypeslib.py +++ b/numpy/tests/test_ctypeslib.py @@ -18,7 +18,7 @@ class TestLoadLibrary(TestCase): try: cdll = load_library('multiarray', np.core.multiarray.__file__) - except ImportError, e: + except ImportError as e: msg = "ctypes is not available on this python: skipping the test" \ " (import error was: %s)" % str(e) print msg @@ -35,7 +35,7 @@ class TestLoadLibrary(TestCase): np.core.multiarray.__file__) except ImportError: print "No distutils available, skipping test." - except ImportError, e: + except ImportError as e: msg = "ctypes is not available on this python: skipping the test" \ " (import error was: %s)" % str(e) print msg |