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

Commit

Permalink
make TPayload struct unhashable, fix #184
Browse files Browse the repository at this point in the history
mutable container should be unhashable
  • Loading branch information
lxyu committed Feb 16, 2016
1 parent 010717e commit daa213d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions tests/test_base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-

import pytest

import thriftpy
from thriftpy.thrift import parse_spec, TType

Expand Down Expand Up @@ -28,10 +30,11 @@ def test_isinstancecheck():
assert isinstance(ab.PersonNotExistsError(), ab2.PersonNotExistsError)


def test_hashable():
def test_unhashable():
ab = thriftpy.load("addressbook.thrift")

hash(ab.Person(name="Tom"))
with pytest.raises(TypeError):
hash(ab.Person(name="Tom"))


def test_default_value():
Expand Down
2 changes: 1 addition & 1 deletion thriftpy/thrift.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def __eq__(self, other):
self.__dict__ == other.__dict__

def __hash__(self):
return super(TPayload, self).__hash__()
raise TypeError("unhashable type: 'thriftpy.thrift.TPayload'")

def __ne__(self, other):
return not self.__eq__(other)
Expand Down

1 comment on commit daa213d

@wbolster
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach is incorrect; see #192

Please sign in to comment.