THRIFT-2621 Add basic default hash code method to python
Client: Python
Patch: Kishor Patil & Jens Geyer
diff --git a/compiler/cpp/src/generate/t_py_generator.cc b/compiler/cpp/src/generate/t_py_generator.cc
index 5d23366..4d155e0 100644
--- a/compiler/cpp/src/generate/t_py_generator.cc
+++ b/compiler/cpp/src/generate/t_py_generator.cc
@@ -797,6 +797,17 @@
endl;
}
+ out << indent() << "def __hash__(self):" << endl;
+ indent_up();
+ indent(out) << "value = PYTHONHASHSEED" << endl;
+ for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
+ indent(out) << "value = (value * 31) ^ hash(self." << (*m_iter)->get_name() + ")" << endl;
+ }
+ indent(out) << "return value" << endl;
+ indent_down();
+ out << endl;
+
+
if (!gen_slots_) {
// Printing utilities so that on the command line thrift
// structs look pretty like dictionaries