Skip to content

Commit

Permalink
Fix hash for value objects with in value objects
Browse files Browse the repository at this point in the history
  • Loading branch information
quiqueporta committed Sep 5, 2018
1 parent b410f00 commit 5c59448
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

1.1.1 (2015-09-05)
------------------

- Fix hash for value objects within value objects.

1.1.0 (2018-09-04)
------------------

Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ Test
> PYTHONPATH=$PYTHONPATH:. mamba
.. |Version Number| image:: https://img.shields.io/badge/version-1.1.0-blue.svg
.. |Version Number| image:: https://img.shields.io/badge/version-1.1.1-blue.svg

.. |Build Status| image:: https://travis-ci.org/quiqueporta/simple-value-object.svg?branch=master
:target: https://travis-ci.org/quiqueporta/simple-value-object
Expand Down
2 changes: 1 addition & 1 deletion simple_value_object/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .value_object import ValueObject
from .decorators import invariant

VERSION = (1, 1, 0, 'final')
VERSION = (1, 1, 1, 'final')
__version__ = VERSION


Expand Down
4 changes: 3 additions & 1 deletion simple_value_object/value_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,12 @@ def __repr__(self):

return "{}({})".format(self.__class__.__name__, ", ".join(args_values))

def __hash__(self):
return self.hash

@property
def hash(self):
return hash(self.__class__) and hash(frozenset(self.__dict__.items()))
return hash(repr(self))


class ArgsSpec(object):
Expand Down
5 changes: 5 additions & 0 deletions specs/value_object_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ def __init__(self, x, y=3):
expect(a_money).to(equal(Money(100, Currency('€'))))
expect(a_money.currency).to(equal(Currency('€')))

with it('can compare hash for value objects within value objects'):
a_money = Money(100, Currency('€'))
another_money = Money(100, Currency('€'))
expect(a_money.__hash__()).to(equal(another_money.__hash__()))

with it('provides a representation'):
class MyPoint(ValueObject):
def __init__(self, x, y=3):
Expand Down

0 comments on commit 5c59448

Please sign in to comment.