Skip to content

Commit

Permalink
Convert to float for comparison with float in IFDRational __eq__
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed May 9, 2021
1 parent ef22a74 commit c04260b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Tests/test_tiff_ifdrational.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def test_sanity():
_test_equal(1, 2, Fraction(1, 2))
_test_equal(1, 2, IFDRational(1, 2))

_test_equal(7, 5, 1.4)


def test_ranges():
for num in range(1, 10):
Expand Down
5 changes: 4 additions & 1 deletion src/PIL/TiffImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,12 @@ def __hash__(self):
return self._val.__hash__()

def __eq__(self, other):
val = self._val
if isinstance(other, IFDRational):
other = other._val
return self._val == other
if isinstance(other, float):
val = float(val)
return val == other

def __getstate__(self):
return [self._val, self._numerator, self._denominator]
Expand Down

0 comments on commit c04260b

Please sign in to comment.