From fbf3fbbd81756588742d43926801b2adfbdd27a6 Mon Sep 17 00:00:00 2001 From: brandon Date: Tue, 10 Dec 2024 11:02:03 -0800 Subject: [PATCH] !! add back in as much type checking as we can now --- src/groundlight/client.py | 7 ++++++- test/integration/test_groundlight.py | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/groundlight/client.py b/src/groundlight/client.py index 41adf1a2..d1d31e08 100644 --- a/src/groundlight/client.py +++ b/src/groundlight/client.py @@ -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: diff --git a/test/integration/test_groundlight.py b/test/integration/test_groundlight.py index c92f2790..01f7956a 100644 --- a/test/integration/test_groundlight.py +++ b/test/integration/test_groundlight.py @@ -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