THRIFT-241. python: Generate a better implementation of __repr__
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@731685 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/generate/t_py_generator.cc b/compiler/cpp/src/generate/t_py_generator.cc
index 85eb3f6..8c9747a 100644
--- a/compiler/cpp/src/generate/t_py_generator.cc
+++ b/compiler/cpp/src/generate/t_py_generator.cc
@@ -614,11 +614,10 @@
// Printing utilities so that on the command line thrift
// structs look pretty like dictionaries
out <<
- indent() << "def __str__(self):" << endl <<
- indent() << " return str(self.__dict__)" << endl <<
- endl <<
indent() << "def __repr__(self):" << endl <<
- indent() << " return repr(self.__dict__)" << endl <<
+ indent() << " L = ['%s=%r' % (key, value)" << endl <<
+ indent() << " for key, value in self.__dict__.iteritems()]" << endl <<
+ indent() << " return '%s(%s)' % (self.__class__.__name__, ', '.join(L))" << endl <<
endl;
// Equality and inequality methods that compare by value