You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2015/11/23 15:21:11 UTC
[jira] [Commented] (THRIFT-162) Thrift structures are unhashable,
preventing them from being used as set elements
[ https://issues.apache.org/jira/browse/THRIFT-162?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15022145#comment-15022145 ]
ASF GitHub Bot commented on THRIFT-162:
---------------------------------------
GitHub user nsuke opened a pull request:
https://github.com/apache/thrift/pull/714
THRIFT-162 Thrift structures are unhashable, preventing them from bei…
…ng used as set elements
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/nsuke/thrift THRIFT-162
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/thrift/pull/714.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #714
----
commit 8d6c200c9b44b3d4bf284cfe0238df7ede94f270
Author: Nobuaki Sukegawa <ns...@apache.org>
Date: 2015-11-17T02:01:17Z
THRIFT-162 Thrift structures are unhashable, preventing them from being used as set elements
Client: Python
Patch: David Reiss, Nobuaki Sukegawa
----
> 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: Python - Compiler, Python - Library
> Reporter: Esteve Fernandez
> Assignee: Aki Sukegawa
> Priority: Minor
> Fix For: 0.9.3
>
> Attachments: immut-no-slots-v1.diff, immut-v2.diff, immut-v3.diff, immut-v4.diff, reading-containers.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 was sent by Atlassian JIRA
(v6.3.4#6332)