Python fastdispatch error message improvements

When overloaded C++ methods are called, the fastdispatch mode sometimes
optimises out the generation of the typecheck typemap code, resulting in
the 'Possible C/C++ prototypes' information not being in the error message.
Now when a TypeError is thrown, the exception message is modified to contain the
'Possible C/C++ prototypes'.

See issue #1293
This commit is contained in:
William S Fulton 2018-07-31 20:00:20 +01:00
commit 4f7406624d
6 changed files with 79 additions and 16 deletions

View file

@ -25,6 +25,13 @@ class MyFoo3(Foo):
def ping(self):
raise MyException("foo", "bar")
class MyFoo4(Foo):
def ping(self, *args):
print(type("bad", "call")) # throws TypeError message: type() takes 1 or 3 arguments
return "Foo4.ping"
# Check that the NotImplementedError raised by MyFoo.ping() is returned by
# MyFoo.pong().
ok = 0
@ -51,7 +58,8 @@ b = launder(a)
try:
b.pong()
except TypeError, e:
if str(e) == "SWIG director type mismatch in output value of type 'std::string'":
# fastdispatch mode adds on Additional Information to the exception message - just check the main exception message exists
if str(e).startswith("SWIG director type mismatch in output value of type 'std::string'"):
ok = 1
else:
print "Unexpected error message: %s" % str(e)
@ -74,6 +82,22 @@ except MyException, e:
if not ok:
raise RuntimeError
# Check that the director returns the appropriate TypeError thrown in a director method
ok = 0
a = MyFoo4()
b = launder(a)
try:
b.pong()
except TypeError as e:
if str(e).startswith("type() takes 1 or 3 arguments"):
ok = 1
else:
print "Unexpected error message: %s" % str(e)
if not ok:
raise RuntimeError
# This is expected to fail with -builtin option
# Throwing builtin classes as exceptions not supported
if not is_python_builtin():