Skip to content

Correct ImageOps.crop border type hint - #9989

Open
lllleolin-max wants to merge 4 commits into
python-pillow:mainfrom
lllleolin-max:fix-imageops-crop-tuple-border
Open

Correct ImageOps.crop border type hint#9989
lllleolin-max wants to merge 4 commits into
python-pillow:mainfrom
lllleolin-max:fix-imageops-crop-tuple-border

Conversation

@lllleolin-max

@lllleolin-max lllleolin-max commented Sep 12, 2026

Copy link
Copy Markdown

ImageOps.crop(im, (1, 2)) and ImageOps.crop(im, (1, 2, 3, 4)) already work through _border(), but type checkers reject them because crop() only annotates border as int.

Changes proposed in this pull request:

  • Match the existing tuple support in the crop() annotation, consistent with expand().
  • Document integer, horizontal/vertical and left/top/right/bottom border forms for both functions, replacing the inaccurate statement that crop() always removes the same border on every side.
  • Add typed crop tests for all three forms.

Validation:

  • With MYPYPATH=src, python3 -m mypy --follow-imports=silent --ignore-missing-imports Tests/test_imageops.py: the new test produces one arg-type error with the old annotation, and passes with the updated annotation.
  • All 49 tests in Tests/test_imageops.py pass with the checkout's ImageOps module and Pillow 12.3.0's prebuilt native extensions on Windows/Python 3.12. The native extensions were not rebuilt.
  • Black, Ruff, Sphinx-lint and git diff --check pass for the changed files.
  • The full Sphinx HTML documentation builds successfully with warnings treated as errors, using the checkout's ImageOps module and Pillow 12.3.0 for the other modules.

Prepared with AI assistance.

Document supported border tuple ordering and cover all border forms.

Assisted-by: OpenAI GPT-6 <noreply@openai.com>
@radarhere radarhere added the 🤖-assisted AI-assisted label Sep 12, 2026
@radarhere

Copy link
Copy Markdown
Member

I've created lllleolin-max#1 with suggestions.

@radarhere radarhere changed the title Correct ImageOps.crop tuple border type annotation Correct ImageOps.crop tuple border type hint Sep 12, 2026
@radarhere radarhere changed the title Correct ImageOps.crop tuple border type hint Correct ImageOps.crop border type hint Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants