summaryrefslogtreecommitdiff
path: root/numpy/core/_exceptions.py
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2019-06-05 00:18:09 -0700
committerEric Wieser <wieser.eric@gmail.com>2019-06-05 19:49:39 -0700
commit2a1b2e5ed87a9dcf39342c394f815ccfbc93b7bd (patch)
tree031aed8e02f035e37d01ee2fa7c185149fdaddc1 /numpy/core/_exceptions.py
parent5971d6099fbb410d9cb0003361c755bee598a1dc (diff)
downloadnumpy-2a1b2e5ed87a9dcf39342c394f815ccfbc93b7bd.tar.gz
BUG: Prevent unsafe string concatenation
This did not handle exceptions correctly. Changed to use python to format the exception like all the others in this file. This also adds quotes around the ufunc name.
Diffstat (limited to 'numpy/core/_exceptions.py')
-rw-r--r--numpy/core/_exceptions.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/numpy/core/_exceptions.py b/numpy/core/_exceptions.py
index 1dcea6255..a1af7a78d 100644
--- a/numpy/core/_exceptions.py
+++ b/numpy/core/_exceptions.py
@@ -37,6 +37,22 @@ class UFuncTypeError(TypeError):
@_display_as_base
+class _UFuncBinaryResolutionError(UFuncTypeError):
+ """ Thrown when a binary resolution fails """
+ def __init__(self, ufunc, dtypes):
+ super().__init__(ufunc)
+ self.dtypes = tuple(dtypes)
+ assert len(self.dtypes) == 2
+
+ def __str__(self):
+ return (
+ "ufunc {!r} cannot use operands with types {!r} and {!r}"
+ ).format(
+ self.ufunc.__name__, *self.dtypes
+ )
+
+
+@_display_as_base
class _UFuncNoLoopError(UFuncTypeError):
""" Thrown when a ufunc loop cannot be found """
def __init__(self, ufunc, dtypes):