[
https://issues.apache.org/jira/browse/THRIFT-162?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12688923#action_12688923
]
Esteve Fernandez edited comment on THRIFT-162 at 3/24/09 3:52 PM:
------------------------------------------------------------------
I still prefer adding slots, but I guess that could be discussed at thrift-dev.
However, I'm not sure I like your implementation of const maps, I'd rather
backport named tuples from Python 2.6, here's the recipe:
http://code.activestate.com/recipes/500261/
It should be fairly easy to check whether we should use collections.namedtuple
(2.6) or our backported version. Something like:
{code}
import sys
if sys.hexversion >= 0x20600f0:
from collections import namedtuple
else:
from thrift.compat import namedtuple
{code}
BTW, I'm sorry, but I won't be able to devote too much time to this issue (and
to Thrift in general) during the next days :-( Feel free to take over it David.
was (Author: esteve):
I still prefer adding slots, but I guess that could be discussed at
thrift-dev. However, I'm not sure I like your implementation of const maps, I'd
rather backport named tuples from Python 2.6, here's the recipe:
http://code.activestate.com/recipes/500261/
It should be fairly easy to check whether we should use collections.namedtuple
(2.6) or our backported version. Something like:
{{code}}
import sys
if sys.hexversion >= 0x20600f0:
from collections import namedtuple
else:
from thrift.compat import namedtuple
{{code}}
BTW, I'm sorry, but I won't be able to devote too much time to this issue (and
to Thrift in general) during the next days :-( Feel free to take over it David.
> Thrift structures are unhashable, preventing them from being used as set
> elements
> ---------------------------------------------------------------------------------
>
> Key: THRIFT-162
> URL: https://issues.apache.org/jira/browse/THRIFT-162
> Project: Thrift
> Issue Type: Bug
> Components: Compiler (Python), Library (Python)
> Reporter: Esteve Fernandez
> Priority: Minor
> Attachments: immut-no-slots-v1.diff, immut-v2.diff,
> thrift-162_annotiations.patch, thrift-162_v2_annotiations.patch,
> thrift_py_hash.patch
>
>
> 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.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.