kernel: bbox/polygon geometry as a pydantic discriminated union (replaces Annotation.geometry: dict) - #72
Merged
Merged
Conversation
Replaces Annotation.geometry: dict[str, object] with a real union discriminated on `type`: BboxGeometry, PolygonGeometry and ClassificationGeometry. The discriminator values are GeometryType members rather than parallel string literals, so a schema's allowed geometries and an annotation's geometry are directly comparable — AnnotationService (#7) needs no translation layer. Variants are frozen and forbid extra fields, so a bbox payload carrying polygon keys is rejected instead of silently validating. Non-positive width/height and polygons with fewer than three points are rejected at the model level; self-intersection is explicitly not validated in M1.
This was referenced Jul 26, 2026
JArmandoAnaya
added a commit
that referenced
this pull request
Aug 21, 2026
…#72) Replaces Annotation.geometry: dict[str, object] with a real union discriminated on `type`: BboxGeometry, PolygonGeometry and ClassificationGeometry. The discriminator values are GeometryType members rather than parallel string literals, so a schema's allowed geometries and an annotation's geometry are directly comparable — AnnotationService (#7) needs no translation layer. Variants are frozen and forbid extra fields, so a bbox payload carrying polygon keys is rejected instead of silently validating. Non-positive width/height and polygons with fewer than three points are rejected at the model level; self-intersection is explicitly not validated in M1.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces
Annotation.geometry: dict[str, object]with a real discriminated union ontype.What landed
kernel/domain/geometry.py—BboxGeometry {x, y, width, height},PolygonGeometry {points: [[x, y], ...]},ClassificationGeometry {}, joined asGeometry = Annotated[..., Field(discriminator="type")].GeometryTypemembers, not parallel string literals, soannotation.geometry.typeis directly comparable to a schema's allowed geometries — AnnotationService (kernel: AnnotationService — schema-validated writes (hard reject: unknown class, disallowed geometry, missing required attribute), provenance, UUID identity #7) needs no translation layer.frozen=True, extra="forbid": a bbox payload carryingpointsis rejected rather than silently validating.width/height(a zero-area box is as meaningless as a negative one), polygons with fewer than three points, and payloads naming aGeometryTypethat has no model yet (mask,polyline, the 3D variants).tests/kernel/test_annotation.py's fixture used abbreviatedw/h; updated towidth/height.Scope note
Acceptance criterion 2 names
AnnotationServiceandallowed_geometries, which belong to #7 and #6 respectively and do not exist yet (kernel/services/is empty;LabelClasscarries a singulargeometry). It is satisfied here at the model level — the union makes the check a plain membership test, proven by a test against the existingLabelClass.geometry. No service was created; #7 still owns the enforcement.Gates
uv run pytestuv run ruff check .uv run ruff format --check .uv run mypy src/visionset/kerneluv run mypy src/visionsetuv run lint-importsscripts/export_openapi.pyAnnotation)Frontend untouched, so frontend gates are not implicated.
Closes #10