Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
None
-
None
-
Patch Available
Description
Let Foo be a Thrift structure:
struct Foo {
1: i32 bar
}
If you want to use it properly as a set element or a as a dictionary key, the autoegenerated Python code will complain about not being hashable:
>>> f1 = Foo()
>>> f1.bar = 1
>>> f2 = Foo()
>>> f2.bar = 1
>>> f1 == f2
True
>>> set([f1]) & set([f2])
set([])
>>> d = {}
>>> d[f1] = 2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable instance
Since Thrift structures already implement _eq_ and _ne, they should implement __hash_ as well. The attached patch tries to mimic the behaviour of the Java compiler, including a HashCodeBuilder class written in Python.
Attachments
Attachments
Issue Links
- depends upon
-
THRIFT-301 Add a create() class method for factory-like instantiation
- Closed
- relates to
-
THRIFT-3388 hash doesn't work on set/list
- Closed