Skip to content
Browse files

ENH: weave: update 'raise' statements.

  • Loading branch information...
1 parent ca93c6c commit 9af9d6df34a4ba5eea0597590a2fef858830b68c warren.weckesser committed
View
12 scipy/weave/accelerate_tools.py
@@ -265,7 +265,7 @@ def lookup_type(x):
elif issubclass(T, InstanceType):
return Instance(x)
else:
- raise NotImplementedError,T
+ raise NotImplementedError(T)
##################################################################
# class ACCELERATE #
@@ -332,7 +332,7 @@ def singleton(self,signature):
weave.build_tools.build_extension(self.module.__name__+'_weave.cpp',verbose=2)
if accelerated_module:
- raise NotImplementedError,'Reload'
+ raise NotImplementedError('Reload')
else:
accelerated_module = __import__(self.module.__name__+'_weave')
@@ -356,10 +356,10 @@ def accelerate(self,signature,identifier):
def code(self,*args):
if len(args) != self.function.func_code.co_argcount:
- raise TypeError,'%s() takes exactly %d arguments (%d given)'%(
- self.function.__name__,
- self.function.func_code.co_argcount,
- len(args))
+ raise TypeError('%s() takes exactly %d arguments (%d given)' %
+ (self.function.__name__,
+ self.function.func_code.co_argcount,
+ len(args)))
signature = tuple( map(lookup_type,args) )
ident = self.function.__name__
return self.accelerate(signature,ident).function_code()
View
2 scipy/weave/base_spec.py
@@ -30,7 +30,7 @@ class base_converter(object):
def set_compiler(self,compiler):
self.compiler = compiler
def type_match(self,value):
- raise NotImplementedError, "You must override method in derived class"
+ raise NotImplementedError("You must override method in derived class")
def build_information(self):
return self._build_information
def type_spec(self,name,value):
View
2 scipy/weave/blitz_spec.py
@@ -101,7 +101,7 @@ def type_spec(self,name,value):
if new_spec.dims > 11:
msg = "Error converting variable '" + name + "'. " \
"blitz only supports arrays up to 11 dimensions."
- raise ValueError, msg
+ raise ValueError(msg)
return new_spec
def template_vars(self,inline=0):
View
4 scipy/weave/build_tools.py
@@ -407,7 +407,7 @@ def configure_temp_dir(temp_dir=None):
if not os.access(temp_dir,os.W_OK):
msg = "Either the temp or build directory wasn't writable. Check" \
" these locations: '%s'" % temp_dir
- raise ValueError, msg
+ raise ValueError(msg)
return temp_dir
def configure_build_dir(build_dir=None):
@@ -434,7 +434,7 @@ def configure_build_dir(build_dir=None):
if not os.access(build_dir,os.W_OK):
msg = "The build directory wasn't writable. Check" \
" this location: '%s'" % build_dir
- raise ValueError, msg
+ raise ValueError(msg)
return os.path.abspath(build_dir)
View
10 scipy/weave/bytecodecompiler.py
@@ -987,7 +987,7 @@ def global_info(self,var_num):
if module and id(module.__dict__) == myHash:
break
else:
- raise ValueError,'Cannot locate module owning %s'%var_name
+ raise ValueError('Cannot locate module owning %s' % var_name)
return module_name,var_name
@@ -1157,7 +1157,7 @@ def LOAD_FAST(self,pc,var_num):
for VV,TT in map(None, self.stack, self.types):
print VV,':',TT
if t is None:
- raise TypeError,'%s used before set?'%v
+ raise TypeError('%s used before set?' % v)
print self.__body
print 'PC',pc
self.push(v,t)
@@ -1288,7 +1288,7 @@ def STORE_FAST(self,pc,var_num):
self.types[var_num] = t
return
- raise TypeError,(t,saveT)
+ raise TypeError((t,saveT))
##################################################################
# MEMBER STORE_GLOBAL #
@@ -1364,7 +1364,7 @@ def JUMP_IF_FALSE(self,pc,delta):
)
self.post(pc+delta,action)
if not isinstance(t, int):
- raise TypeError, 'Invalid comparison type %s'%t
+ raise TypeError('Invalid comparison type %s' % t)
self.emit('if (%s) {\n'%v)
@@ -1386,7 +1386,7 @@ def RETURN_VALUE(self,pc):
if hasattr(self,'rtype'):
if t is None:
return # just the extra return
- raise ValueError,'multiple returns: (v=%s, t=%s)' % (v, t)
+ raise ValueError('multiple returns: (v=%s, t=%s)' % (v, t))
self.rtype = t
if t is None:
self.emit('return;')
View
4 scipy/weave/catalog.py
@@ -295,7 +295,7 @@ def get_catalog(module_path,mode='r'):
"""
if mode not in ['c','r','w','n']:
msg = " mode must be 'c', 'n', 'r', or 'w'. See anydbm for more info"
- raise ValueError, msg
+ raise ValueError(msg)
catalog_file = catalog_path(module_path)
if (catalog_file is not None) \
and ((dumb and os.path.exists(catalog_file+'.dat')) \
@@ -680,7 +680,7 @@ def add_function_persistent(self,code,function):
os.remove(f)
cat = get_catalog(cat_dir,mode)
if cat is None:
- raise ValueError, 'Failed to access a catalog for storing functions'
+ raise ValueError('Failed to access a catalog for storing functions')
# Prabhu was getting some corrupt catalog errors. I'll put a try/except
# to protect against this, but should really try and track down the issue.
function_list = [function]
View
4 scipy/weave/ext_tools.py
@@ -366,7 +366,7 @@ def compile(self,location='.',compiler=None, verbose = 0, **kw):
compiler_name = compiler,
verbose = verbose, **kw)
if not success:
- raise SystemError, 'Compilation failed'
+ raise SystemError('Compilation failed')
def generate_file_name(module_name,module_location):
module_file = os.path.join(module_location,module_name)
@@ -420,7 +420,7 @@ def assign_variable_types(variables,local_dict = {}, global_dict = {},
errors[var] = ("Unable to convert variable '"+ var +
"' to a C++ type.")
if errors:
- raise TypeError, format_error_msg(errors)
+ raise TypeError(format_error_msg(errors))
if auto_downcast:
variable_specs = downcast(variable_specs)
View
14 scipy/weave/inline_tools.py
@@ -327,13 +327,13 @@ def inline(code,arg_names=[],local_dict = None, global_dict = None,
if msg[:16] == "Conversion Error":
pass
else:
- raise TypeError, msg
+ raise TypeError(msg)
except NameError, msg:
msg = str(msg).strip()
if msg[:16] == "Conversion Error":
pass
else:
- raise NameError, msg
+ raise NameError(msg)
except KeyError:
pass
# 2. try function catalog
@@ -372,13 +372,13 @@ def attempt_function_call(code,local_dict,global_dict):
if msg[:16] == "Conversion Error":
pass
else:
- raise TypeError, msg
+ raise TypeError(msg)
except NameError, msg:
msg = str(msg).strip()
if msg[:16] == "Conversion Error":
pass
else:
- raise NameError, msg
+ raise NameError(msg)
except KeyError:
pass
# 2. try catalog cache.
@@ -397,13 +397,13 @@ def attempt_function_call(code,local_dict,global_dict):
if msg[:16] == "Conversion Error":
pass
else:
- raise TypeError, msg
+ raise TypeError(msg)
except NameError, msg:
msg = str(msg).strip()
if msg[:16] == "Conversion Error":
pass
else:
- raise NameError, msg
+ raise NameError(msg)
# 3. try persistent catalog
module_dir = global_dict.get('__file__',None)
function_list = function_catalog.get_functions(code,module_dir)
@@ -416,7 +416,7 @@ def attempt_function_call(code,local_dict,global_dict):
except: # should specify argument types here.
pass
# if we get here, the function wasn't found
- raise ValueError, 'function with correct signature not found'
+ raise ValueError('function with correct signature not found')
def inline_function_code(code,arg_names,local_dict=None,
global_dict=None,auto_downcast = 1,
View
2 scipy/weave/platform_info.py
@@ -113,7 +113,7 @@ def get_compiler_dir(compiler_name):
exe_name = compiler_exe_name(compiler_obj)
exe_path = compiler_exe_path(exe_name)
if not exe_path:
- raise ValueError, "The '%s' compiler was not found." % compiler_name
+ raise ValueError("The '%s' compiler was not found." % compiler_name)
chk_sum = check_sum(exe_path)
restore_sys_argv()
View
12 scipy/weave/size_check.py
@@ -98,7 +98,7 @@ def binary_op_size(xx,yy):
res[i] = x[i]
else:
# offer more information here about which variables.
- raise ValueError, "frames are not aligned"
+ raise ValueError("frames are not aligned")
return res
class dummy_array(object):
@@ -170,14 +170,14 @@ def __getitem__(self,indices):
if not isinstance(indices, tuple):
indices = (indices,)
if Ellipsis in indices:
- raise IndexError, "Ellipsis not currently supported"
+ raise IndexError("Ellipsis not currently supported")
new_dims = []
dim = 0
for index in indices:
try:
dim_len = self.shape[dim]
except IndexError:
- raise IndexError, "To many indices specified"
+ raise IndexError("To many indices specified")
#if (type(index) is SliceType and index.start == index.stop == index.step):
if (index is empty_slice):
@@ -237,11 +237,11 @@ def __getitem__(self,indices):
#this reduces the array dimensions by one
pass
else:
- raise IndexError, "Index out of range"
+ raise IndexError("Index out of range")
dim += 1
new_dims.extend(self.shape[dim:])
if 0 in new_dims:
- raise IndexError, "Zero length slices not currently supported"
+ raise IndexError("Zero length slices not currently supported")
return dummy_array(new_dims,1)
def __repr__(self):
val = str((self.name, str(self.shape)))
@@ -269,7 +269,7 @@ def reduction(ary,axis=0):
if axis < 0:
axis += len(ary.shape)
if axis < 0 or axis >= len(ary.shape):
- raise ValueError, "Dimension not in array"
+ raise ValueError("Dimension not in array")
new_dims = list(ary.shape[:axis]) + list(ary.shape[axis+1:])
return dummy_array(new_dims,1)
View
4 scipy/weave/swig2_spec.py
@@ -266,7 +266,7 @@ def init_info(self, runtime=0):
elif rv == 3:
self.support_code.append(swigptr2.swigptr2_code_v3)
else:
- raise AssertionError, "Unsupported version of the SWIG runtime:", rv
+ raise AssertionError("Unsupported version of the SWIG runtime: %s" % rv)
self.support_code.append(swig2_common_code)
@@ -339,7 +339,7 @@ def type_spec(self,name,value):
elif swig_ob_type == 'pyswig':
pycobj = 2
else:
- raise AssertionError, "Does not look like a SWIG object: %s"%value
+ raise AssertionError("Does not look like a SWIG object: %s" % value)
if pycobj:
class_name = value.__class__.__name__
View
2 scipy/weave/tests/test_size_check.py
@@ -124,7 +124,7 @@ def generic_wrap(self,a,expr):
if 0 not in desired:
msg = '%s raised IndexError in dummy_array, but forms\n' \
'valid array shape -> %s' % (expr, str(desired))
- raise AttributeError, msg
+ raise AttributeError(msg)
def generic_1d(self,expr):
a = np.arange(10)
self.generic_wrap(a,expr)
View
23 scipy/weave/tests/weave_test_utils.py
@@ -108,20 +108,17 @@ def move_file (src, dst,
return dst
if not isfile(src):
- raise DistutilsFileError, \
- "can't move '%s': not a regular file" % src
+ raise DistutilsFileError("can't move '%s': not a regular file" % src)
if isdir(dst):
dst = os.path.join(dst, basename(src))
elif exists(dst):
- raise DistutilsFileError, \
- "can't move '%s': destination '%s' already exists" % \
- (src, dst)
+ raise DistutilsFileError("can't move '%s': destination '%s' already "
+ "exists" % (src, dst))
if not isdir(dirname(dst)):
- raise DistutilsFileError, \
- "can't move '%s': destination '%s' not a valid path" % \
- (src, dst)
+ raise DistutilsFileError("can't move '%s': destination '%s' not a "
+ "valid path" % (src, dst))
copy_it = 0
try:
@@ -130,8 +127,8 @@ def move_file (src, dst,
if num == errno.EXDEV:
copy_it = 1
else:
- raise DistutilsFileError, \
- "couldn't move '%s' to '%s': %s" % (src, dst, msg)
+ raise DistutilsFileError("couldn't move '%s' to '%s': %s" %
+ (src, dst, msg))
if copy_it:
distutils.file_util.copy_file(src, dst)
@@ -142,9 +139,7 @@ def move_file (src, dst,
os.unlink(dst)
except os.error:
pass
- raise DistutilsFileError, \
- ("couldn't move '%s' to '%s' by copy/delete: " +
- "delete '%s' failed: %s") % \
- (src, dst, src, msg)
+ raise DistutilsFileError("couldn't move '%s' to '%s' by copy/delete: "
+ "delete '%s' failed: %s" % (src, dst, src, msg))
return dst

0 comments on commit 9af9d6d

Please sign in to comment.
Something went wrong with that request. Please try again.