summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbhay Raghuvanshi <abhayaman669@gmail.com>2021-03-19 01:49:20 +0530
committerGitHub <noreply@github.com>2021-03-18 14:19:20 -0600
commit9c68c2f7b1b2128a3b4af2134565f60d286fa8b9 (patch)
tree6ce82ac0a4e3074f89b0d2b883d2e02345f90b3d
parentbb7a31a6a852ecc64d3f7cffb70121fc8bef20eb (diff)
downloadnumpy-9c68c2f7b1b2128a3b4af2134565f60d286fa8b9.tar.gz
MAINT: Added Chain exceptions where appropriate (#18394)
* Added chain exception in _bits_of func * Added chain exception * Added chain exception in unixccompiler.py * Added chain exception in config.py * Added chain exception in fcompiler __init__.py * Added chain exception in compaq.py * Added chain exception in format.py * Updated raise chain exception * STY: Break long line. Co-authored-by: Charles Harris <charlesr.harris@gmail.com>
-rw-r--r--numpy/core/_type_aliases.py3
-rw-r--r--numpy/distutils/command/config.py5
-rw-r--r--numpy/distutils/conv_template.py4
-rw-r--r--numpy/distutils/fcompiler/__init__.py4
-rw-r--r--numpy/distutils/fcompiler/compaq.py4
-rw-r--r--numpy/distutils/unixccompiler.py4
-rw-r--r--numpy/lib/format.py8
7 files changed, 16 insertions, 16 deletions
diff --git a/numpy/core/_type_aliases.py b/numpy/core/_type_aliases.py
index de90fd818..67addef48 100644
--- a/numpy/core/_type_aliases.py
+++ b/numpy/core/_type_aliases.py
@@ -46,7 +46,8 @@ def _bits_of(obj):
info = next(v for v in _concrete_typeinfo.values() if v.type is obj)
except StopIteration:
if obj in _abstract_types.values():
- raise ValueError("Cannot count the bits of an abstract type")
+ msg = "Cannot count the bits of an abstract type"
+ raise ValueError(msg) from None
# some third-party type - make a best-guess
return dtype(obj).itemsize * 8
diff --git a/numpy/distutils/command/config.py b/numpy/distutils/command/config.py
index 8b735677a..1f4037bb5 100644
--- a/numpy/distutils/command/config.py
+++ b/numpy/distutils/command/config.py
@@ -64,7 +64,7 @@ class config(old_config):
% (e, self.compiler.__class__.__name__)
print(textwrap.dedent("""\
============================================================================"""))
- raise distutils.errors.DistutilsPlatformError(msg)
+ raise distutils.errors.DistutilsPlatformError(msg) from e
# After MSVC is initialized, add an explicit /MANIFEST to linker
# flags. See issues gh-4245 and gh-4101 for details. Also
@@ -97,9 +97,8 @@ class config(old_config):
try:
ret = mth(*((self,)+args))
except (DistutilsExecError, CompileError) as e:
- str(e)
self.compiler = save_compiler
- raise CompileError
+ raise CompileError from e
self.compiler = save_compiler
return ret
diff --git a/numpy/distutils/conv_template.py b/numpy/distutils/conv_template.py
index 65efab062..90e07f8b1 100644
--- a/numpy/distutils/conv_template.py
+++ b/numpy/distutils/conv_template.py
@@ -285,7 +285,7 @@ def process_file(source):
try:
code = process_str(''.join(lines))
except ValueError as e:
- raise ValueError('In "%s" loop at %s' % (sourcefile, e))
+ raise ValueError('In "%s" loop at %s' % (sourcefile, e)) from None
return '#line 1 "%s"\n%s' % (sourcefile, code)
@@ -322,7 +322,7 @@ def main():
try:
writestr = process_str(allstr)
except ValueError as e:
- raise ValueError("In %s loop at %s" % (file, e))
+ raise ValueError("In %s loop at %s" % (file, e)) from None
outfile.write(writestr)
diff --git a/numpy/distutils/fcompiler/__init__.py b/numpy/distutils/fcompiler/__init__.py
index 812461538..d7579e976 100644
--- a/numpy/distutils/fcompiler/__init__.py
+++ b/numpy/distutils/fcompiler/__init__.py
@@ -610,7 +610,7 @@ class FCompiler(CCompiler):
self.spawn(command, display=display)
except DistutilsExecError as e:
msg = str(e)
- raise CompileError(msg)
+ raise CompileError(msg) from None
def module_options(self, module_dirs, module_build_dir):
options = []
@@ -678,7 +678,7 @@ class FCompiler(CCompiler):
self.spawn(command)
except DistutilsExecError as e:
msg = str(e)
- raise LinkError(msg)
+ raise LinkError(msg) from None
else:
log.debug("skipping %s (up-to-date)", output_filename)
diff --git a/numpy/distutils/fcompiler/compaq.py b/numpy/distutils/fcompiler/compaq.py
index 1a356866a..351a43dd7 100644
--- a/numpy/distutils/fcompiler/compaq.py
+++ b/numpy/distutils/fcompiler/compaq.py
@@ -87,11 +87,11 @@ class CompaqVisualFCompiler(FCompiler):
except IOError as e:
if not "vcvarsall.bat" in str(e):
print("Unexpected IOError in", __file__)
- raise e
+ raise
except ValueError as e:
if not "'path'" in str(e):
print("Unexpected ValueError in", __file__)
- raise e
+ raise
executables = {
'version_cmd' : ['<F90>', "/what"],
diff --git a/numpy/distutils/unixccompiler.py b/numpy/distutils/unixccompiler.py
index 0cd2d243e..fb91f1789 100644
--- a/numpy/distutils/unixccompiler.py
+++ b/numpy/distutils/unixccompiler.py
@@ -54,7 +54,7 @@ def UnixCCompiler__compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts
extra_postargs, display = display)
except DistutilsExecError as e:
msg = str(e)
- raise CompileError(msg)
+ raise CompileError(msg) from None
# add commandline flags to dependency file
if deps:
@@ -131,7 +131,7 @@ def UnixCCompiler_create_static_lib(self, objects, output_libname,
display = display)
except DistutilsExecError as e:
msg = str(e)
- raise LibError(msg)
+ raise LibError(msg) from None
else:
log.debug("skipping %s (up-to-date)", output_filename)
return
diff --git a/numpy/lib/format.py b/numpy/lib/format.py
index 5d951e262..ac5f75fba 100644
--- a/numpy/lib/format.py
+++ b/numpy/lib/format.py
@@ -378,7 +378,7 @@ def _wrap_header(header, version):
header_prefix = magic(*version) + struct.pack(fmt, hlen + padlen)
except struct.error:
msg = "Header length {} too big for version={}".format(hlen, version)
- raise ValueError(msg)
+ raise ValueError(msg) from None
# Pad the header with spaces and a final newline such that the magic
# string, the header-length short and the header are aligned on a
@@ -595,7 +595,7 @@ def _read_array_header(fp, version):
d = safe_eval(header)
except SyntaxError as e:
msg = "Cannot parse header: {!r}\nException: {!r}"
- raise ValueError(msg.format(header, e))
+ raise ValueError(msg.format(header, e)) from None
if not isinstance(d, dict):
msg = "Header is not a dictionary: {!r}"
raise ValueError(msg.format(d))
@@ -614,9 +614,9 @@ def _read_array_header(fp, version):
raise ValueError(msg.format(d['fortran_order']))
try:
dtype = descr_to_dtype(d['descr'])
- except TypeError:
+ except TypeError as e:
msg = "descr is not a valid dtype descriptor: {!r}"
- raise ValueError(msg.format(d['descr']))
+ raise ValueError(msg.format(d['descr'])) from e
return d['shape'], d['fortran_order'], dtype