THRIFT-241. python: Generate a better implementation of __repr__
authorDavid Reiss <dreiss@apache.org>
Mon, 5 Jan 2009 20:14:52 +0000 (20:14 +0000)
committerDavid Reiss <dreiss@apache.org>
Mon, 5 Jan 2009 20:14:52 +0000 (20:14 +0000)
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@731685 13f79535-47bb-0310-9956-ffa450edef68

compiler/cpp/src/generate/t_py_generator.cc

index 85eb3f6..8c9747a 100644 (file)
@@ -614,11 +614,10 @@ void t_py_generator::generate_py_struct_definition(ofstream& out,
   // 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