From 9e525d20fb296674bdb69a7a1e5b7530099046ae Mon Sep 17 00:00:00 2001 From: Nathan Perkins Date: Sat, 16 Dec 2023 13:30:54 +0000 Subject: [PATCH 1/3] cleanup of mypy errors --- darwin/future/core/items/set_item_layout.py | 9 --------- darwin/future/meta/queries/item.py | 2 +- darwin/future/tests/core/fixtures.py | 2 +- .../future/tests/core/items/test_set_stage_to_items.py | 5 ++++- darwin/future/tests/core/items/test_tag_items.py | 7 +++++-- darwin/future/tests/core/items/test_untag_items.py | 7 +++++-- darwin/future/tests/data_objects/test_darwin.py | 10 +++++----- darwin/future/tests/meta/objects/test_itemmeta.py | 10 +++++----- darwin/future/tests/meta/objects/test_workflowmeta.py | 2 +- darwin/future/tests/meta/queries/test_item.py | 10 +++++----- 10 files changed, 32 insertions(+), 32 deletions(-) diff --git a/darwin/future/core/items/set_item_layout.py b/darwin/future/core/items/set_item_layout.py index 841dee7b2..2a2a3a837 100644 --- a/darwin/future/core/items/set_item_layout.py +++ b/darwin/future/core/items/set_item_layout.py @@ -2,13 +2,10 @@ from typing import Dict -from pydantic import ValidationError - from darwin.future.core.client import ClientCore from darwin.future.core.types.common import JSONType from darwin.future.data_objects.item import ItemLayout from darwin.future.data_objects.typing import UnknownType -from darwin.future.exceptions import BadRequest def set_item_layout( @@ -31,12 +28,6 @@ def set_item_layout( Returns: JSONType: The response data. """ - if not isinstance(layout, ItemLayout): - try: - layout = ItemLayout(**layout) - except (ValueError, ValidationError): - raise BadRequest("Invalid layout provided") - assert ( filters ), "No parameters provided, please provide at least one non-dataset id filter" diff --git a/darwin/future/meta/queries/item.py b/darwin/future/meta/queries/item.py index 6f3e09f6e..1fedfbae6 100644 --- a/darwin/future/meta/queries/item.py +++ b/darwin/future/meta/queries/item.py @@ -80,7 +80,7 @@ def delete(self) -> None: filters = {"item_ids": [str(item) for item in ids]} delete_list_of_items(self.client, team_slug, dataset_ids, filters) - def move_to_folder(self, path) -> None: + def move_to_folder(self, path: str) -> None: if "team_slug" not in self.meta_params: raise ValueError("Must specify team_slug to query items") diff --git a/darwin/future/tests/core/fixtures.py b/darwin/future/tests/core/fixtures.py index 8c7434416..2557a3f97 100644 --- a/darwin/future/tests/core/fixtures.py +++ b/darwin/future/tests/core/fixtures.py @@ -135,7 +135,7 @@ def base_item_json_response() -> dict: @pytest.fixture -def base_items_json_response(base_item_json_response) -> dict: +def base_items_json_response(base_item_json_response: dict) -> dict: return {"items": [base_item_json_response]} diff --git a/darwin/future/tests/core/items/test_set_stage_to_items.py b/darwin/future/tests/core/items/test_set_stage_to_items.py index 204b63f94..a1c2954b5 100644 --- a/darwin/future/tests/core/items/test_set_stage_to_items.py +++ b/darwin/future/tests/core/items/test_set_stage_to_items.py @@ -1,8 +1,11 @@ +from typing import Dict + import pytest import responses from darwin.future.core.client import ClientCore from darwin.future.core.items.set_stage_to_items import set_stage_to_items +from darwin.future.data_objects.typing import UnknownType from darwin.future.exceptions import BadRequest from darwin.future.tests.core.fixtures import * @@ -44,7 +47,7 @@ def test_set_stage_to_items_filters_error(base_client: ClientCore) -> None: dataset_ids = [1, 2, 3] stage_id = "123456" workflow_id = "123456" - filters = {} + filters: Dict[str, UnknownType] = {} responses.add( responses.POST, diff --git a/darwin/future/tests/core/items/test_tag_items.py b/darwin/future/tests/core/items/test_tag_items.py index d673c0c48..ea82f31ac 100644 --- a/darwin/future/tests/core/items/test_tag_items.py +++ b/darwin/future/tests/core/items/test_tag_items.py @@ -1,8 +1,11 @@ +from typing import Dict + import pytest import responses from darwin.future.core.client import ClientCore from darwin.future.core.items.tag_items import tag_items +from darwin.future.data_objects.typing import UnknownType from darwin.future.exceptions import BadRequest from darwin.future.tests.core.fixtures import * @@ -42,7 +45,7 @@ def test_tag_items_empty_filters_error(base_client: ClientCore) -> None: dataset_ids = [1, 2, 3] tag_id = 123456 # this should raise an error as no filters are provided - filters = {} + filters: Dict[str, UnknownType] = {} responses.add( responses.POST, @@ -89,6 +92,6 @@ def test_tag_items_bad_request_error(base_client: ClientCore) -> None: client=base_client, team_slug=team_slug, dataset_ids=dataset_ids, - tag_id=tag_id, + tag_id=tag_id, # type: ignore filters=filters, ) diff --git a/darwin/future/tests/core/items/test_untag_items.py b/darwin/future/tests/core/items/test_untag_items.py index 9933ea302..c6381754e 100644 --- a/darwin/future/tests/core/items/test_untag_items.py +++ b/darwin/future/tests/core/items/test_untag_items.py @@ -1,8 +1,11 @@ +from typing import Dict + import pytest import responses from darwin.future.core.client import ClientCore from darwin.future.core.items.untag_items import untag_items +from darwin.future.data_objects.typing import UnknownType from darwin.future.exceptions import BadRequest from darwin.future.tests.core.fixtures import * @@ -42,7 +45,7 @@ def test_untag_items_empty_filters_error(base_client: ClientCore) -> None: dataset_ids = [1, 2, 3] tag_id = 123456 # this should raise an error as no filters are provided - filters = {} + filters: Dict[str, UnknownType] = {} responses.add( responses.DELETE, @@ -89,6 +92,6 @@ def test_untag_items_bad_request_error(base_client: ClientCore) -> None: client=base_client, team_slug=team_slug, dataset_ids=dataset_ids, - tag_id=tag_id, + tag_id=tag_id, # type: ignore filters=filters, ) diff --git a/darwin/future/tests/data_objects/test_darwin.py b/darwin/future/tests/data_objects/test_darwin.py index 36fd30767..7497a9894 100644 --- a/darwin/future/tests/data_objects/test_darwin.py +++ b/darwin/future/tests/data_objects/test_darwin.py @@ -17,7 +17,7 @@ def raw_json() -> dict: return raw_json -def test_loads_base_darwin_v2(raw_json: dict): +def test_loads_base_darwin_v2(raw_json: dict) -> None: test = DarwinV2.parse_obj(raw_json) assert len(test.annotations) == 3 assert isinstance(test.annotations[0], BoundingBoxAnnotation) @@ -25,22 +25,22 @@ def test_loads_base_darwin_v2(raw_json: dict): assert isinstance(test.annotations[2], PolygonAnnotation) -def test_bbox_annotation(raw_json: dict): +def test_bbox_annotation(raw_json: dict) -> None: bounds_annotation = raw_json["annotations"][0] BoundingBoxAnnotation.parse_obj(bounds_annotation) -def test_ellipse_annotation(raw_json: dict): +def test_ellipse_annotation(raw_json: dict) -> None: ellipse_annotation = raw_json["annotations"][1] EllipseAnnotation.parse_obj(ellipse_annotation) -def test_polygon_annotation(raw_json: dict): +def test_polygon_annotation(raw_json: dict) -> None: polygon_annotation = raw_json["annotations"][2] PolygonAnnotation.parse_obj(polygon_annotation) -def test_polygon_bbx_validator(raw_json: dict): +def test_polygon_bbx_validator(raw_json: dict) -> None: polygon_annotation = raw_json["annotations"][2] without_bbx = polygon_annotation.copy() del without_bbx["bounding_box"] diff --git a/darwin/future/tests/meta/objects/test_itemmeta.py b/darwin/future/tests/meta/objects/test_itemmeta.py index f25bd3118..2b423dc3e 100644 --- a/darwin/future/tests/meta/objects/test_itemmeta.py +++ b/darwin/future/tests/meta/objects/test_itemmeta.py @@ -102,7 +102,7 @@ def test_move_to_folder_raises_on_incorrect_parameters(item: Item) -> None: json={}, ) with pytest.raises(BadRequest): - item.move_to_folder(path) + item.move_to_folder(path) # type: ignore def test_move_to_folder_with_bad_team_slug(item: Item) -> None: @@ -160,7 +160,7 @@ def test_set_priority_raises_on_incorrect_parameters(item: Item) -> None: json={}, ) with pytest.raises(BadRequest): - item.set_priority(priority) + item.set_priority(priority) # type: ignore def test_set_priority_with_bad_team_slug(item: Item) -> None: @@ -259,7 +259,7 @@ def test_set_layout_raises_on_incorrect_parameters(item: Item) -> None: item.meta_params["dataset_id"] layout = "invalid_layout" with pytest.raises(AssertionError): - item.set_layout(layout) + item.set_layout(layout) # type: ignore def test_set_layout_with_bad_team_slug(item: Item) -> None: @@ -298,7 +298,7 @@ def test_tag_bad_input(item: Item) -> None: with responses.RequestsMock(): tag_id = "123456" with pytest.raises(BadRequest) as excinfo: - item.tag(tag_id) + item.tag(tag_id) # type: ignore (msg,) = excinfo.value.args assert msg == "tag_id must be an integer, got " @@ -332,7 +332,7 @@ def test_untag_bad_input(item: Item) -> None: with responses.RequestsMock(): tag_id = "123456" with pytest.raises(BadRequest) as excinfo: - item.untag(tag_id) + item.untag(tag_id) # type: ignore (msg,) = excinfo.value.args assert msg == "tag_id must be an integer, got " diff --git a/darwin/future/tests/meta/objects/test_workflowmeta.py b/darwin/future/tests/meta/objects/test_workflowmeta.py index 6c8e39bb3..d15371e52 100644 --- a/darwin/future/tests/meta/objects/test_workflowmeta.py +++ b/darwin/future/tests/meta/objects/test_workflowmeta.py @@ -7,7 +7,7 @@ def test_item_set_stage_with_stage_object( - workflow: Workflow, base_single_workflow_object, base_items_json_response + workflow: Workflow, base_single_workflow_object: list, base_items_json_response: dict ) -> None: with responses.RequestsMock() as rsps: rsps.add( diff --git a/darwin/future/tests/meta/queries/test_item.py b/darwin/future/tests/meta/queries/test_item.py index 554de856d..de434cfdd 100644 --- a/darwin/future/tests/meta/queries/test_item.py +++ b/darwin/future/tests/meta/queries/test_item.py @@ -146,7 +146,7 @@ def test_move_to_folder_raises_on_incorrect_parameters( json={}, ) with pytest.raises(BadRequest): - item_query.move_to_folder(path) + item_query.move_to_folder(path) # type: ignore def test_set_priority( @@ -223,7 +223,7 @@ def test_set_priority_raises_on_incorrect_parameters( json={}, ) with pytest.raises(BadRequest): - item_query.set_priority(priority) + item_query.set_priority(priority) # type: ignore def test_restore( @@ -341,7 +341,7 @@ def test_set_layout_raises_on_incorrect_parameters( items[0].meta_params["dataset_id"] layout = "invalid_layout" with pytest.raises(AssertionError): - item_query.set_layout(layout) + item_query.set_layout(layout) # type: ignore def test_tag(item_query: ItemQuery, items_json: List[dict], items: List[Item]) -> None: @@ -386,7 +386,7 @@ def test_tag_bad_request( with responses.RequestsMock(): tag_id = "123456" with pytest.raises(BadRequest) as excinfo: - item_query.tag(tag_id) + item_query.tag(tag_id) # type: ignore (msg,) = excinfo.value.args assert msg == "tag_id must be an integer, got " @@ -435,6 +435,6 @@ def test_untag_bad_request( with responses.RequestsMock(): tag_id = "123456" with pytest.raises(BadRequest) as excinfo: - item_query.untag(tag_id) + item_query.untag(tag_id) # type: ignore (msg,) = excinfo.value.args assert msg == "tag_id must be an integer, got " From 83f50870a9fdd3614f3845aac81521ba89dbda6c Mon Sep 17 00:00:00 2001 From: Nathan Perkins Date: Mon, 18 Dec 2023 13:19:17 +0000 Subject: [PATCH 2/3] linting --- darwin/future/tests/core/items/test_tag_items.py | 2 +- darwin/future/tests/core/items/test_untag_items.py | 2 +- darwin/future/tests/meta/objects/test_itemmeta.py | 10 +++++----- darwin/future/tests/meta/objects/test_workflowmeta.py | 4 +++- darwin/future/tests/meta/queries/test_item.py | 10 +++++----- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/darwin/future/tests/core/items/test_tag_items.py b/darwin/future/tests/core/items/test_tag_items.py index ea82f31ac..d3eebe70e 100644 --- a/darwin/future/tests/core/items/test_tag_items.py +++ b/darwin/future/tests/core/items/test_tag_items.py @@ -92,6 +92,6 @@ def test_tag_items_bad_request_error(base_client: ClientCore) -> None: client=base_client, team_slug=team_slug, dataset_ids=dataset_ids, - tag_id=tag_id, # type: ignore + tag_id=tag_id, # type: ignore filters=filters, ) diff --git a/darwin/future/tests/core/items/test_untag_items.py b/darwin/future/tests/core/items/test_untag_items.py index c6381754e..7d1e0da4e 100644 --- a/darwin/future/tests/core/items/test_untag_items.py +++ b/darwin/future/tests/core/items/test_untag_items.py @@ -92,6 +92,6 @@ def test_untag_items_bad_request_error(base_client: ClientCore) -> None: client=base_client, team_slug=team_slug, dataset_ids=dataset_ids, - tag_id=tag_id, # type: ignore + tag_id=tag_id, # type: ignore filters=filters, ) diff --git a/darwin/future/tests/meta/objects/test_itemmeta.py b/darwin/future/tests/meta/objects/test_itemmeta.py index 2b423dc3e..9c676082a 100644 --- a/darwin/future/tests/meta/objects/test_itemmeta.py +++ b/darwin/future/tests/meta/objects/test_itemmeta.py @@ -102,7 +102,7 @@ def test_move_to_folder_raises_on_incorrect_parameters(item: Item) -> None: json={}, ) with pytest.raises(BadRequest): - item.move_to_folder(path) # type: ignore + item.move_to_folder(path) # type: ignore def test_move_to_folder_with_bad_team_slug(item: Item) -> None: @@ -160,7 +160,7 @@ def test_set_priority_raises_on_incorrect_parameters(item: Item) -> None: json={}, ) with pytest.raises(BadRequest): - item.set_priority(priority) # type: ignore + item.set_priority(priority) # type: ignore def test_set_priority_with_bad_team_slug(item: Item) -> None: @@ -259,7 +259,7 @@ def test_set_layout_raises_on_incorrect_parameters(item: Item) -> None: item.meta_params["dataset_id"] layout = "invalid_layout" with pytest.raises(AssertionError): - item.set_layout(layout) # type: ignore + item.set_layout(layout) # type: ignore def test_set_layout_with_bad_team_slug(item: Item) -> None: @@ -298,7 +298,7 @@ def test_tag_bad_input(item: Item) -> None: with responses.RequestsMock(): tag_id = "123456" with pytest.raises(BadRequest) as excinfo: - item.tag(tag_id) # type: ignore + item.tag(tag_id) # type: ignore (msg,) = excinfo.value.args assert msg == "tag_id must be an integer, got " @@ -332,7 +332,7 @@ def test_untag_bad_input(item: Item) -> None: with responses.RequestsMock(): tag_id = "123456" with pytest.raises(BadRequest) as excinfo: - item.untag(tag_id) # type: ignore + item.untag(tag_id) # type: ignore (msg,) = excinfo.value.args assert msg == "tag_id must be an integer, got " diff --git a/darwin/future/tests/meta/objects/test_workflowmeta.py b/darwin/future/tests/meta/objects/test_workflowmeta.py index d15371e52..950fff2d8 100644 --- a/darwin/future/tests/meta/objects/test_workflowmeta.py +++ b/darwin/future/tests/meta/objects/test_workflowmeta.py @@ -7,7 +7,9 @@ def test_item_set_stage_with_stage_object( - workflow: Workflow, base_single_workflow_object: list, base_items_json_response: dict + workflow: Workflow, + base_single_workflow_object: list, + base_items_json_response: dict, ) -> None: with responses.RequestsMock() as rsps: rsps.add( diff --git a/darwin/future/tests/meta/queries/test_item.py b/darwin/future/tests/meta/queries/test_item.py index de434cfdd..23b3d41a7 100644 --- a/darwin/future/tests/meta/queries/test_item.py +++ b/darwin/future/tests/meta/queries/test_item.py @@ -146,7 +146,7 @@ def test_move_to_folder_raises_on_incorrect_parameters( json={}, ) with pytest.raises(BadRequest): - item_query.move_to_folder(path) # type: ignore + item_query.move_to_folder(path) # type: ignore def test_set_priority( @@ -223,7 +223,7 @@ def test_set_priority_raises_on_incorrect_parameters( json={}, ) with pytest.raises(BadRequest): - item_query.set_priority(priority) # type: ignore + item_query.set_priority(priority) # type: ignore def test_restore( @@ -341,7 +341,7 @@ def test_set_layout_raises_on_incorrect_parameters( items[0].meta_params["dataset_id"] layout = "invalid_layout" with pytest.raises(AssertionError): - item_query.set_layout(layout) # type: ignore + item_query.set_layout(layout) # type: ignore def test_tag(item_query: ItemQuery, items_json: List[dict], items: List[Item]) -> None: @@ -386,7 +386,7 @@ def test_tag_bad_request( with responses.RequestsMock(): tag_id = "123456" with pytest.raises(BadRequest) as excinfo: - item_query.tag(tag_id) # type: ignore + item_query.tag(tag_id) # type: ignore (msg,) = excinfo.value.args assert msg == "tag_id must be an integer, got " @@ -435,6 +435,6 @@ def test_untag_bad_request( with responses.RequestsMock(): tag_id = "123456" with pytest.raises(BadRequest) as excinfo: - item_query.untag(tag_id) # type: ignore + item_query.untag(tag_id) # type: ignore (msg,) = excinfo.value.args assert msg == "tag_id must be an integer, got " From 8d6626ed1248d7e8eda02b29bd4150e082261e08 Mon Sep 17 00:00:00 2001 From: John Wilkie Date: Thu, 6 Jun 2024 17:33:21 +0100 Subject: [PATCH 3/3] Added required imports --- darwin/future/core/items/set_item_layout.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/darwin/future/core/items/set_item_layout.py b/darwin/future/core/items/set_item_layout.py index f9321142a..43aacb859 100644 --- a/darwin/future/core/items/set_item_layout.py +++ b/darwin/future/core/items/set_item_layout.py @@ -2,10 +2,13 @@ from typing import Dict +from pydantic import ValidationError + from darwin.future.core.client import ClientCore from darwin.future.core.types.common import JSONType from darwin.future.data_objects.item import ItemLayout from darwin.future.data_objects.typing import UnknownType +from darwin.future.exceptions import BadRequest def set_item_layout(