Skip to content

Return typed crop results and safe JSON diagnostics - #213

Open
leblancfg wants to merge 1 commit into
v2-type-hintsfrom
issue-211-json-diagnostics
Open

leblancfg wants to merge 1 commit into
v2-type-hintsfrom
issue-211-json-diagnostics

Conversation

@leblancfg

@leblancfg leblancfg commented Jul 15, 2026 •

Copy link
Copy Markdown
Owner

JSON/result layer above typing PR #221

Native stack #222, from master upward: #221 → #213 → #214 → #219. Review/merge bottom-up using GitHub's stack controls after approval and green CI. A group merge includes all lower unmerged PRs; GitHub rebases the remaining stack after a partial merge. Do not use the former reverse-order/manual-base-edit recipe.

Nothing has been merged, tagged, released, or published. The restack preserves the existing PRs and review discussions.

API introduced here

result = cropper.crop(source)
if result.image is not None:
    Image.fromarray(result.image).save('cropped.jpg')
print(result.diagnostics.crop_rectangle)
  • crop() always returns CropResult with image and a CropDiagnostics dataclass.
  • No diagnostics flag, tuple unpacking, array impersonation, or per-call state stored on Cropper.
  • No-face/uncroppable results have image=None and a reason; unreadable inputs and invalid configuration still raise.
  • Independent per-call diagnostics; generated ndarray equality is disabled on the result record.
  • V1 callers must read .image and check that field for None. README, API/quickstart/overview, notebook, and tests reflect this contract; Prepare v2 migration FAQ and actionable compatibility errors #219 adds the full migration FAQ.

Implementation

  • diagnostics.py contains typed result records, independent of printing/file handling.
  • reporting.py owns CLI serialization, atomic writes, and source/output/redirected-stream alias safeguards.
  • The CLI has a direct read/crop/write flow rather than callback plumbing or shared mutable diagnostic dictionaries.
  • The detector adapter decodes named boxes, landmarks, and scores before consumers use them.
  • The flat JSON schema and JSON-only stderr remain intact on errors and with verbose output.
  • Module naming cleanup includes timing.py; alignment/migration modules arrive in their own PRs.
  • New feature code and consumer examples obey the strict typing checks inherited from Add type hints with ty and Ruff checks #221.

Validation

  • This layer independently passes lint, ty and Ruff lint/format checks, and 118 tests.
  • The full stack passes 174 tests and preserves the previously tested final implementation; all 15 updated CI matrix configurations are green. Final wheel/sdist and installed-package checks also passed.

Closes #211. SDK decisions #215–#218 remain for discussion before publication.

Toolchain sync

The ty/Ruff configuration, dependencies, recipes, and CI changes live in #221. This layer inherits them, uses Ruff formatting/import order, and updates consumer checks to ty-specific expected diagnostics. Local ty, Ruff lint/format, and all 118 tests pass. Runtime API and stack order are unchanged.

@leblancfg leblancfg changed the title Add JSON crop diagnostics Add opt-in crop diagnostics and safe JSON output Sep 17, 2026
@leblancfg
leblancfg added this pull request to stack #220 September 19, 2026 12:56
@leblancfg leblancfg changed the title Add opt-in crop diagnostics and safe JSON output Return typed crop results and safe JSON diagnostics Sep 19, 2026
@leblancfg
leblancfg removed this pull request from stack #220 September 19, 2026 17:14
@leblancfg
leblancfg force-pushed the issue-211-json-diagnostics branch from 526f9da to 9034633 Compare September 19, 2026 17:14
@leblancfg
leblancfg changed the base branch from master to v2-type-hints September 19, 2026 17:14
@leblancfg
leblancfg added this pull request to stack #222 September 19, 2026 17:14
@leblancfg
leblancfg force-pushed the issue-211-json-diagnostics branch from 9034633 to 6af41f9 Compare September 19, 2026 18:25

This branch has not been deployed

No deployments
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.

Add JSON diagnostics for crop results

1 participant