Skip to content

refactor(draw): extract require_pil_image guard into _ink#207

Draft
wkentaro wants to merge 1 commit into
mainfrom
refactor/require-pil-image-guard
Draft

refactor(draw): extract require_pil_image guard into _ink#207
wkentaro wants to merge 1 commit into
mainfrom
refactor/require-pil-image-guard

Conversation

@wkentaro

Copy link
Copy Markdown
Owner

Closes #192.

The in-place draw primitives line_ and polygon_ each repeated the same
three-line PIL image type guard. This extracts it into require_pil_image in
imgviz/draw/_ink.py, alongside the existing require_fill_or_outline, and
replaces both inline copies. Behavior and the TypeError message are unchanged.

Summary

  • Add require_pil_image(image) to imgviz/draw/_ink.py.
  • Replace the inline guard in line_ and polygon_ with a call to it.

Scope note: only line_ and polygon_ carry the inline guard on main today
(arrow_ arrives with #193 and can adopt the helper there). The other in-place
primitives (circle_, ellipse_, rectangle_, etc.) never had a guard;
applying one to them is a behavior change (they would start raising TypeError
instead of a Pillow AttributeError), so that uniform rollout is tracked
separately rather than folded into this dedupe.

Test plan

  • full suite uv run --extra all pytest -n=auto tests (251 passed)
  • the existing polygon_ "rejects non-PIL image" test still passes, exercising the extracted helper
  • uv run ruff check, ty check on the touched files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extract require_pil_image guard to dedupe PIL type check across draw primitives

1 participant