Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup of mypy for darwin future #757

Merged
merged 4 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion darwin/future/meta/queries/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,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")

Expand Down
2 changes: 1 addition & 1 deletion darwin/future/tests/core/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]}


Expand Down
5 changes: 4 additions & 1 deletion darwin/future/tests/core/items/test_set_stage_to_items.py
Original file line number Diff line number Diff line change
@@ -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 *

Expand Down Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions darwin/future/tests/core/items/test_tag_items.py
Original file line number Diff line number Diff line change
@@ -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 *

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
)
7 changes: 5 additions & 2 deletions darwin/future/tests/core/items/test_untag_items.py
Original file line number Diff line number Diff line change
@@ -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 *

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
)
10 changes: 5 additions & 5 deletions darwin/future/tests/data_objects/test_darwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,30 @@ 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.model_validate(raw_json)
assert len(test.annotations) == 3
assert isinstance(test.annotations[0], BoundingBoxAnnotation)
assert isinstance(test.annotations[1], EllipseAnnotation)
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.model_validate(bounds_annotation)


def test_ellipse_annotation(raw_json: dict):
def test_ellipse_annotation(raw_json: dict) -> None:
ellipse_annotation = raw_json["annotations"][1]
EllipseAnnotation.model_validate(ellipse_annotation)


def test_polygon_annotation(raw_json: dict):
def test_polygon_annotation(raw_json: dict) -> None:
polygon_annotation = raw_json["annotations"][2]
PolygonAnnotation.model_validate(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"]
Expand Down
10 changes: 5 additions & 5 deletions darwin/future/tests/meta/objects/test_itemmeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 <class 'str'>"

Expand Down Expand Up @@ -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 <class 'str'>"

Expand Down
4 changes: 3 additions & 1 deletion darwin/future/tests/meta/objects/test_workflowmeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@


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(
Expand Down
10 changes: 5 additions & 5 deletions darwin/future/tests/meta/queries/test_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 <class 'str'>"

Expand Down Expand Up @@ -435,7 +435,7 @@ 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 <class 'str'>"

Expand Down
Loading