Structs misbehave when hashed #184

Closed
springheeledjak opened this Issue Feb 13, 2016 · 1 comment

Comments

Projects
None yet
1 participant
@springheeledjak

It appears that __hash__ is not overridden for Structs, which is probably not a good thing. They should either (a) be considered non-hashable as dicts are, or (b) have a __hash__ implementation that agrees with __eq__. The former is the more Pythonic, as mutable objects are not valid hash keys.

As an example, the assert below will fail:

#!/usr/bin/env python3
import io
import thriftpy

fp = io.StringIO('''
struct Foo {
    1: i32 id;
}
''')
Foo = thriftpy.load_fp(fp, 'foo.thrift').Foo

assert(set([Foo('bar')]) == set([Foo('bar')]))

Instead, it should probably throw something like TypeError: unhashable type: 'thriftpy.thrift.TPayload'

@springheeledjak

This comment has been minimized.

Show comment
Hide comment

Thanks! 😄

dan-blanchard added a commit to dan-blanchard/thriftpy that referenced this issue May 6, 2016

make TPayload struct unhashable, fix #184
mutable container should be unhashable

dan-blanchard added a commit to dan-blanchard/thriftpy that referenced this issue May 6, 2016

@pyup-bot pyup-bot referenced this issue in scieloorg/opac_proc Aug 18, 2016

Closed

Initial Update #10

@pyup-bot pyup-bot referenced this issue in scieloorg/scielo-manager Aug 26, 2016

Closed

Pin thriftpy to latest version 0.3.9 #1314

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment