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.
Follow-up to #192 / #207. Extracting
require_pil_image(now inimgviz/draw/_ink.py) surfaced that the guard is applied inconsistently: onlyline_andpolygon_validate theirimageargument.The gap
These in-place
_-suffixed primitives acceptimage: PIL.Image.Imagebut donot call
require_pil_image, so passing a non-PIL image (e.g. a numpy array)raises a confusing
AttributeErrorfrom deep inside Pillow instead of the clearTypeError: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
AttributeErrortoTypeError), so itdeserves its own deliberate change with tests, rather than being folded into a
pure dedupe.
What to build
require_pil_image(image)as the first line of each unguarded in-placeprimitive listed above.
TypeErrormessage (mirroring the existing
polygon_test), or one parametrized testcovering all of them.
ruff,tyclean; 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.