From 4f3192093d819d7933342d9dd2560b00b95c55c0 Mon Sep 17 00:00:00 2001 From: David Reiss Date: Wed, 29 Apr 2009 23:35:01 +0000 Subject: [PATCH] THRIFT-471. python: Generated exceptions should implement __str__ This makes Python stack dumps properly show the exception content. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@770002 13f79535-47bb-0310-9956-ffa450edef68 --- compiler/cpp/src/generate/t_py_generator.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/compiler/cpp/src/generate/t_py_generator.cc b/compiler/cpp/src/generate/t_py_generator.cc index cd7f760e..343c982b 100644 --- a/compiler/cpp/src/generate/t_py_generator.cc +++ b/compiler/cpp/src/generate/t_py_generator.cc @@ -637,6 +637,16 @@ void t_py_generator::generate_py_struct_definition(ofstream& out, 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 << -- 2.17.1