Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

Structs misbehave when hashed #184

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

Structs misbehave when hashed #184

springheeledjak opened this issue Feb 13, 2016 · 1 comment

Comments

@springheeledjak
Copy link

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
Copy link
Author

Thanks! 😄

dan-blanchard pushed a commit to dan-blanchard/thriftpy that referenced this issue May 6, 2016
mutable container should be unhashable
dan-blanchard pushed a commit to dan-blanchard/thriftpy that referenced this issue May 6, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant