Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Tests/test_tiff_ifdrational.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import math
from fractions import Fraction
from pathlib import Path

Expand Down Expand Up @@ -38,6 +39,18 @@ def test_sanity() -> None:
_test_equal(7, 5, 1.4)


def test_float() -> None:
# float() must agree with ==, int() and repr(), which all use the
# normalized fraction
r = IFDRational(1.5, 3)
assert r == 0.5
assert float(r) == 0.5

# Integer numerator and 0/0 (nan) cases
assert float(IFDRational(4, 2)) == 2.0
assert math.isnan(float(IFDRational(0, 0)))


def test_ranges() -> None:
for num in range(1, 10):
for denom in range(1, 10):
Expand Down
1 change: 1 addition & 0 deletions src/PIL/TiffImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ def __setstate__(self, state: list[float | Fraction | IntegralLike]) -> None:
__ceil__ = _delegate("__ceil__")
__floor__ = _delegate("__floor__")
__round__ = _delegate("__round__")
__float__ = _delegate("__float__")
# Python >= 3.11
if hasattr(Fraction, "__int__"):
__int__ = _delegate("__int__")
Expand Down
Loading