Skip to content

Allow arithmetic between two IFDRational instances - #10321

Merged
radarhere merged 2 commits into
python-pillow:mainfrom
LemonCondor:fix/ifdrational-arithmetic
Oct 27, 2026
Merged

radarhere merged 2 commits into
python-pillow:mainfrom
LemonCondor:fix/ifdrational-arithmetic

Conversation

@LemonCondor

Copy link
Copy Markdown
Contributor

Changes proposed in this pull request:

  • IFDRational(1, 2) + IFDRational(1, 3) (and -, *, /, //, %) raised TypeError: Fraction returns NotImplemented for the wrapper, and Python does not try the reflected method when both operands have the same type. This affects arithmetic on EXIF values such as GPS degrees/minutes/seconds.
  • When the delegated call returns NotImplemented and the other operand is an IFDRational, retry with its underlying value. Other comparisons (e.g. the signedness check for nan values) are unchanged.
  • Add a test.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@radarhere

Copy link
Copy Markdown
Member

Hi. Does this relate to a bug that you experienced, would like fixed and will help you? Or is this just AI finding and fixing a bug by itself?

@radarhere radarhere added the 🤖-assisted AI-assisted label Oct 26, 2026
Comment thread src/PIL/TiffImagePlugin.py Outdated
Comment thread Tests/test_tiff_ifdrational.py Outdated
@radarhere
radarhere enabled auto-merge (squash) October 27, 2026 08:23
@radarhere
radarhere force-pushed the fix/ifdrational-arithmetic branch 3 times, most recently from a3377b5 to 065ca69 Compare October 27, 2026 10:35
@radarhere
radarhere force-pushed the fix/ifdrational-arithmetic branch from 065ca69 to c8798b1 Compare October 27, 2026 10:45
@radarhere
radarhere merged commit fbb949d into python-pillow:main Oct 27, 2026
74 of 78 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🤖-assisted AI-assisted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants