Skip to content

Commit

Permalink
fix for field name
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 committed Dec 28, 2023
1 parent 194acdd commit b3912e5
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/ome_types/_mixins/_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,18 @@ def _field_name(cls, item: Any) -> str:
raise TypeError( # pragma: no cover
f"Expected an instance of {AnnotationInstances}, got {item!r}"
)

item_type = type(item)
# where 10 is the length of "Annotation"
return item.__class__.__name__[:-10].lower() + "_annotations"
field_name = item_type.__name__[:-10].lower() + "_annotations"
if hasattr(cls, field_name):
return field_name

Check warning on line 113 in src/ome_types/_mixins/_collections.py

View check run for this annotation

Codecov / codecov/patch

src/ome_types/_mixins/_collections.py#L113

Added line #L113 was not covered by tests
for annotation_type in AnnotationInstances:
if issubclass(item_type, annotation_type):
return annotation_type.__name__[:-10].lower() + "_annotations"
raise TypeError( # pragma: no cover
f"Could not find field name for {item_type.__name__}"
)


ShapeType = Union[Rectangle, Mask, Point, Ellipse, Line, Polyline, Polygon, Label]
Expand Down

0 comments on commit b3912e5

Please sign in to comment.