Skip to content

Commit

Permalink
Fix hashing
Browse files Browse the repository at this point in the history
Fixes #31.
  • Loading branch information
Perlence committed Feb 20, 2023
1 parent 2407aa8 commit 0000e51
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Version 0.10
**Changes:**

- Fixed GraceEffect.durationTime `#34 <https://github.com/Perlence/PyGuitarPro/issues/34>`_.
- Fixed hashing `#31 <https://github.com/Perlence/PyGuitarPro/issues/31>`_.


Version 0.9.2
Expand Down
10 changes: 6 additions & 4 deletions guitarpro/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ def __eq__(self, other):
return self._value_ == other._value_
return super().__eq__(other)

def __hash__(self):
if self._name_ == 'unknown':
return hash(self._value_)
return hash(self._name_)


def hashableAttrs(cls=None, repr=True):
"""A fully hashable attrs decorator.
Expand Down Expand Up @@ -1132,16 +1137,13 @@ class Chord:
ninth: Optional['ChordAlteration'] = None
eleventh: Optional['ChordAlteration'] = None
firstFret: Optional[int] = None
strings: List[int] = attr.Factory(list)
strings: List[int] = attr.Factory(lambda self: [-1] * self.length, takes_self=True)
barres: List['Barre'] = attr.Factory(list)
omissions: List[bool] = attr.Factory(list)
fingerings: List[Fingering] = attr.Factory(list)
show: Optional[bool] = None
newFormat: Optional[bool] = None

def __attrs_post_init__(self):
self.strings = [-1] * self.length

@property
def notes(self):
return [string for string in self.strings if string >= 0]
Expand Down
1 change: 1 addition & 0 deletions tests/test_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def testReadWriteEquals(tmpdir, filename):
gp.write(songA, destpath)
songB = gp.parse(destpath)
assert songA == songB
assert hash(songA) == hash(songB)


@pytest.mark.parametrize('source, targetExt', CONVERSION_TESTS)
Expand Down

0 comments on commit 0000e51

Please sign in to comment.