Overloaded C++ function Python wrappers now raise a TypeError instead of NotImplementedError
Occurs when the types passed are incorrect. This change means there is now consistency with non-overloaded function wrappers which have always raised TypeError when the incorrect types are passed. See issue #1293
This commit is contained in:
parent
8f224694e7
commit
fd651ff4e2
6 changed files with 32 additions and 14 deletions
|
|
@ -95,14 +95,18 @@ if li_std_string_extra.test_value_basic_overload(123) != "int":
|
|||
|
||||
try:
|
||||
li_std_string_extra.test_value_basic_overload([x])
|
||||
raise RuntimeError, "should throw NotImplementedError"
|
||||
except NotImplementedError:
|
||||
raise RuntimeError, "should throw TypeError"
|
||||
except TypeError as e:
|
||||
if str(e).find("Possible C/C++ prototypes are:") == -1:
|
||||
raise RuntimeError("Incorrect error message text:\n{}".format(e))
|
||||
pass
|
||||
|
||||
try:
|
||||
li_std_string_extra.test_value_basic_overload([123])
|
||||
raise RuntimeError, "should throw NotImplementedError"
|
||||
except NotImplementedError:
|
||||
raise RuntimeError, "should throw TypeError"
|
||||
except TypeError as e:
|
||||
if str(e).find("Possible C/C++ prototypes are:") == -1:
|
||||
raise RuntimeError("Incorrect error message text:\n{}".format(e))
|
||||
pass
|
||||
|
||||
# Global variables
|
||||
|
|
|
|||
|
|
@ -549,14 +549,9 @@ def checkOverload(t, name, val, delta, prevval, limit):
|
|||
if t.ovr_str(val + delta) == name:
|
||||
raise RuntimeError, "bad " + name + " typemap"
|
||||
if val == limit:
|
||||
# Should raise NotImplementedError here since this is the largest integral type
|
||||
raise RuntimeError, "bad " + name + " typemap"
|
||||
except NotImplementedError:
|
||||
# NotImplementedError is expected only if this is the most extreme type
|
||||
if val != limit:
|
||||
# Should raise TypeError here since this is the largest integral type
|
||||
raise RuntimeError, "bad " + name + " typemap"
|
||||
except TypeError:
|
||||
# TypeError is raised instead if swig is run with -O or -fastdispatch
|
||||
if val != limit:
|
||||
raise RuntimeError, "bad " + name + " typemap"
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,5 @@ if varargs.test_plenty("Hello", 1, 2) != "Hello":
|
|||
try:
|
||||
varargs.test_plenty("Hello", 1, 2, 3)
|
||||
raise RuntimeError
|
||||
except NotImplementedError:
|
||||
pass
|
||||
except TypeError:
|
||||
pass
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue