Author: dreiss
Date: Wed Apr 29 23:35:01 2009
New Revision: 770002
URL: http://svn.apache.org/viewvc?rev=770002&view=rev
Log:
THRIFT-471. python: Generated exceptions should implement __str__
This makes Python stack dumps properly show the exception content.
Modified:
incubator/thrift/trunk/compiler/cpp/src/generate/t_py_generator.cc
Modified: incubator/thrift/trunk/compiler/cpp/src/generate/t_py_generator.cc
URL:
http://svn.apache.org/viewvc/incubator/thrift/trunk/compiler/cpp/src/generate/t_py_generator.cc?rev=770002&r1=770001&r2=770002&view=diff
==============================================================================
--- incubator/thrift/trunk/compiler/cpp/src/generate/t_py_generator.cc
(original)
+++ incubator/thrift/trunk/compiler/cpp/src/generate/t_py_generator.cc Wed Apr
29 23:35:01 2009
@@ -637,6 +637,16 @@
generate_py_struct_reader(out, tstruct);
generate_py_struct_writer(out, tstruct);
+ // For exceptions only, generate a __str__ method. This is
+ // because when raised exceptions are printed to the console, __repr__
+ // isn't used. See python bug #5882
+ if (is_exception) {
+ out <<
+ indent() << "def __str__(self):" << endl <<
+ indent() << " return repr(self)" << endl <<
+ endl;
+ }
+
// Printing utilities so that on the command line thrift
// structs look pretty like dictionaries
out <<