Skip to content

Raise ValueError if ImageOps border has unsupported format - #9426

Merged
radarhere merged 2 commits into
python-pillow:mainfrom
veeceey:fix/border-validation-and-rgba-docs
Apr 24, 2026
Merged

Raise ValueError if ImageOps border has unsupported format#9426
radarhere merged 2 commits into
python-pillow:mainfrom
veeceey:fix/border-validation-and-rgba-docs

Conversation

@veeceey

@veeceey veeceey commented Feb 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fix bug in ImageOps._border(): When given a tuple with a length other than 2 or 4 (e.g. a 1-tuple or 3-tuple), the function raised an unhelpful UnboundLocalError because the left, top, right, bottom variables were never assigned. This now raises a clear ValueError with a descriptive message instead.

  • Document rgba() color format in ImageColor: The rgba(red, green, blue, alpha) color string format has been supported in code and tested for a long time, but was missing from the ImageColor documentation. This adds it to the list of supported color string formats.

Test plan

  • Added parametrized test test_expand_invalid_border that verifies ValueError is raised for 1-tuple, 3-tuple, and 5-tuple border values
  • Verified existing tests still pass (ruff and black checks pass)
  • Manually verified the fix resolves the UnboundLocalError

Comment thread Tests/test_imageops.py Outdated