diff --git a/src/pya/pya/pyaModule.cc b/src/pya/pya/pyaModule.cc index 9670a0736..ecfb35c3c 100644 --- a/src/pya/pya/pyaModule.cc +++ b/src/pya/pya/pyaModule.cc @@ -2687,6 +2687,12 @@ PythonModule::make_classes (const char *mod_name) add_python_doc (*c, mt, int (mid), tl::to_string (tr ("This method is also available as 'str(object)'"))); } + } else if (name == "hash" && m_first->compatible_with_num_args (0)) { + + // The hash method is also routed via the tp_hash implementation + alt_names.push_back ("__hash__"); + add_python_doc (*c, mt, int (mid), tl::to_string (tr ("This method is also available as 'hash(object)'"))); + } else if (name == "inspect" && m_first->compatible_with_num_args (0)) { // The str method is also routed via the tp_str implementation diff --git a/testdata/python/dbTransTest.py b/testdata/python/dbTransTest.py index 8f7643f45..b3423b01e 100644 --- a/testdata/python/dbTransTest.py +++ b/testdata/python/dbTransTest.py @@ -530,6 +530,14 @@ class DBTransTests(unittest.TestCase): self.assertEqual(t1.hash() == t3.hash(), False) self.assertEqual(t1.hash() == t4a.hash(), False) self.assertEqual(t1.hash() == t4b.hash(), False) + self.assertEqual(hash(t1) == hash(t2), True) + self.assertEqual(hash(t1) == hash(t3), False) + self.assertEqual(hash(t1) == hash(t4a), False) + self.assertEqual(hash(t1) == hash(t4b), False) + self.assertEqual(t1.__hash__() == t2.__hash__(), True) + self.assertEqual(t1.__hash__() == t3.__hash__(), False) + self.assertEqual(t1.__hash__() == t4a.__hash__(), False) + self.assertEqual(t1.__hash__() == t4b.__hash__(), False) # Transformations can't be used as hash keys currently if False: