Skip to content

Commit

Permalink
!! add back in as much type checking as we can now
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon-groundlight committed Dec 10, 2024
1 parent 4da2633 commit fbf3fbb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/groundlight/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1111,8 +1111,13 @@ def add_label(
"""
if isinstance(rois, str):
raise TypeError("rois must be a list of ROI objects. CLI support is not implemented")
if isinstance(label, int):

# NOTE: bool is a subclass of int
if type(label) == int: # noqa: E721
label = str(label)
elif not isinstance(label, (str, Label)):
raise TypeError("label must be a string or integer")

if isinstance(image_query, ImageQuery):
image_query_id = image_query.id
else:
Expand Down
10 changes: 10 additions & 0 deletions test/integration/test_groundlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,16 @@ def test_add_label_names(gl: Groundlight, image_query_yes: ImageQuery, image_que
gl.add_label(iqid_no, "NO")
gl.add_label(iqid_no, "no")

with pytest.raises(TypeError):
gl.add_label(iqid_yes, None) # type: ignore
with pytest.raises(TypeError):
import IPython; IPython.embed() # type: ignore
gl.add_label(iqid_yes, True) # type: ignore
with pytest.raises(TypeError):
gl.add_label(iqid_yes, False) # type: ignore
with pytest.raises(TypeError):
gl.add_label(iqid_yes, b"YES") # type: ignore


def test_label_conversion_produces_strings():
# In our code, it's easier to work with enums, but we allow users to pass in strings or enums
Expand Down

0 comments on commit fbf3fbb

Please sign in to comment.