Fixed #185 for pymod branch

This commit is contained in:
Matthias Koefferlein 2018-10-14 23:42:10 +02:00
parent dd9d46da38
commit 90c03140b3
2 changed files with 14 additions and 0 deletions

View File

@ -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

View File

@ -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: