Skip to content

Apply require_pil_image uniformly across in-place draw primitives #208

@wkentaro

Description

@wkentaro

Follow-up to #192 / #207. Extracting require_pil_image (now in
imgviz/draw/_ink.py) surfaced that the guard is applied inconsistently: only
line_ and polygon_ validate their image argument.

The gap

These in-place _-suffixed primitives accept image: PIL.Image.Image but do
not call require_pil_image, so passing a non-PIL image (e.g. a numpy array)
raises a confusing AttributeError from deep inside Pillow instead of the clear
TypeError:

  • circle_, ellipse_, rectangle_, triangle_, star_, pie_, text_,
    text_in_rectangle_

(All five review passes on #207 independently flagged this.)

Why it was kept out of #207

#192's acceptance criteria scoped the work to primitives carrying the inline
guard
. Adding the guard to the functions above is a behavior change (their
error type for bad input changes from AttributeError to TypeError), so it
deserves its own deliberate change with tests, rather than being folded into a
pure dedupe.

What to build

  • Call require_pil_image(image) as the first line of each unguarded in-place
    primitive listed above.
  • Add a per-primitive "rejects non-PIL image" test asserting the TypeError
    message (mirroring the existing polygon_ test), or one parametrized test
    covering all of them.
  • ruff, ty clean; full suite green.

Decision for the maintainer

This standardizes the error contract across the in-place draw API. If any of
these functions should intentionally stay permissive, note which and why.

Metadata

Metadata

Assignees

Labels

ready-for-agentFully specified, ready for an AFK agent to pick up

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions