Skip to content

Commit 68f1951

Browse files
GitHKAndrei Neagu
andauthored
♻️ Maintenance: mypy dynamic-sidecar (#6126)
Co-authored-by: Andrei Neagu <[email protected]>
1 parent 423efb3 commit 68f1951

File tree

30 files changed

+145
-127
lines changed

30 files changed

+145
-127
lines changed

.github/workflows/ci-testing-deploy.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,6 @@ jobs:
12121212
run: ./ci/github/unit-testing/dynamic-sidecar.bash install
12131213
- name: typecheck
12141214
run: ./ci/github/unit-testing/dynamic-sidecar.bash typecheck
1215-
continue-on-error: true
12161215
- name: test
12171216
if: always()
12181217
run: ./ci/github/unit-testing/dynamic-sidecar.bash test

packages/dask-task-models-library/src/dask_task_models_library/container_tasks/io.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
from pathlib import Path
44
from typing import Any, ClassVar, TypeAlias, Union
55

6-
from models_library.basic_regex import MIME_TYPE_RE, PROPERTY_KEY_RE
6+
from models_library.basic_regex import MIME_TYPE_RE
77
from models_library.generics import DictModel
8+
from models_library.services_types import ServicePortKey
89
from pydantic import (
910
AnyUrl,
1011
BaseModel,
11-
ConstrainedStr,
1212
Extra,
1313
Field,
1414
StrictBool,
@@ -81,10 +81,6 @@ class Config:
8181
}
8282

8383

84-
class PortKey(ConstrainedStr):
85-
regex = PROPERTY_KEY_RE
86-
87-
8884
PortValue: TypeAlias = Union[
8985
StrictBool,
9086
StrictInt,
@@ -97,7 +93,7 @@ class PortKey(ConstrainedStr):
9793
]
9894

9995

100-
class TaskInputData(DictModel[PortKey, PortValue]):
96+
class TaskInputData(DictModel[ServicePortKey, PortValue]):
10197
class Config:
10298
schema_extra: ClassVar[dict[str, Any]] = {
10399
"examples": [
@@ -115,7 +111,7 @@ class Config:
115111
PortSchemaValue: TypeAlias = Union[PortSchema, FilePortSchema]
116112

117113

118-
class TaskOutputDataSchema(DictModel[PortKey, PortSchemaValue]):
114+
class TaskOutputDataSchema(DictModel[ServicePortKey, PortSchemaValue]):
119115
#
120116
# NOTE: Expected output data is only determined at runtime. A possibility
121117
# would be to create pydantic models dynamically but dask serialization
@@ -144,7 +140,7 @@ class Config:
144140
}
145141

146142

147-
class TaskOutputData(DictModel[PortKey, PortValue]):
143+
class TaskOutputData(DictModel[ServicePortKey, PortValue]):
148144
@classmethod
149145
def from_task_output(
150146
cls, schema: TaskOutputDataSchema, output_folder: Path, output_file_ext: str

packages/service-library/src/servicelib/long_running_tasks/_task.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
from typing import Any, Protocol
1010
from uuid import uuid4
1111

12-
from models_library.api_schemas_long_running_tasks.base import ProgressPercent
12+
from models_library.api_schemas_long_running_tasks.base import (
13+
ProgressPercent,
14+
TaskProgress,
15+
)
1316
from pydantic import PositiveFloat
1417

1518
from ._errors import (
@@ -19,7 +22,7 @@
1922
TaskNotCompletedError,
2023
TaskNotFoundError,
2124
)
22-
from ._models import TaskId, TaskName, TaskProgress, TaskResult, TaskStatus, TrackedTask
25+
from ._models import TaskId, TaskName, TaskResult, TaskStatus, TrackedTask
2326

2427
logger = logging.getLogger(__name__)
2528

@@ -349,8 +352,7 @@ async def close(self) -> None:
349352

350353

351354
class TaskProtocol(Protocol):
352-
# NOTE: when using **kwargs pyright complains. this might be a bug that should be fixed soon
353-
async def __call__(self, task_progress: TaskProgress, *task_kwargs: Any) -> Any:
355+
async def __call__(self, progress: TaskProgress, *args: Any, **kwargs: Any) -> Any:
354356
...
355357

356358
@property
@@ -366,7 +368,7 @@ def start_task(
366368
task_context: TaskContext | None = None,
367369
task_name: str | None = None,
368370
fire_and_forget: bool = False,
369-
**task_kwargs,
371+
**task_kwargs: Any,
370372
) -> TaskId:
371373
"""
372374
Creates a background task from an async function.

packages/simcore-sdk/src/simcore_sdk/node_ports_v2/nodeports_v2.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import logging
2+
from collections.abc import Callable, Coroutine
23
from pathlib import Path
3-
from typing import Any, Callable, Coroutine
4+
from typing import Any
45

56
from models_library.api_schemas_storage import LinkType
67
from models_library.basic_types import IDStr
78
from models_library.projects import ProjectIDStr
89
from models_library.projects_nodes_io import NodeIDStr
10+
from models_library.services_types import ServicePortKey
911
from models_library.users import UserID
1012
from pydantic import BaseModel, Field, ValidationError
1113
from pydantic.error_wrappers import flatten_errors
@@ -20,7 +22,7 @@
2022
from ..node_ports_v2.port import SetKWargs
2123
from .links import ItemConcreteValue, ItemValue
2224
from .port_utils import is_file_type
23-
from .ports_mapping import InputsList, OutputsList, PortKey
25+
from .ports_mapping import InputsList, OutputsList
2426

2527
log = logging.getLogger(__name__)
2628

@@ -74,7 +76,7 @@ async def outputs(self) -> OutputsList:
7476
return self.internal_outputs
7577

7678
async def get_value_link(
77-
self, item_key: PortKey, *, file_link_type: LinkType
79+
self, item_key: ServicePortKey, *, file_link_type: LinkType
7880
) -> ItemValue | None:
7981
try:
8082
return await (await self.inputs)[item_key].get_value(
@@ -89,7 +91,7 @@ async def get_value_link(
8991
)
9092

9193
async def get(
92-
self, item_key: PortKey, progress_bar: ProgressBarData | None = None
94+
self, item_key: ServicePortKey, progress_bar: ProgressBarData | None = None
9395
) -> ItemConcreteValue | None:
9496
try:
9597
return await (await self.inputs)[item_key].get(progress_bar)
@@ -99,7 +101,9 @@ async def get(
99101
# if this fails it will raise an exception
100102
return await (await self.outputs)[item_key].get(progress_bar)
101103

102-
async def set(self, item_key: PortKey, item_value: ItemConcreteValue) -> None:
104+
async def set(
105+
self, item_key: ServicePortKey, item_value: ItemConcreteValue
106+
) -> None:
103107
# first try to set the inputs.
104108
try:
105109
the_updated_inputs = await self.inputs
@@ -139,7 +143,9 @@ async def _auto_update_from_db(self) -> None:
139143

140144
async def set_multiple(
141145
self,
142-
port_values: dict[PortKey, tuple[ItemConcreteValue | None, SetKWargs | None]],
146+
port_values: dict[
147+
ServicePortKey, tuple[ItemConcreteValue | None, SetKWargs | None]
148+
],
143149
*,
144150
progress_bar: ProgressBarData,
145151
) -> None:

packages/simcore-sdk/src/simcore_sdk/node_ports_v2/port.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
from typing import Any
88

99
from models_library.api_schemas_storage import LinkType
10-
from models_library.basic_regex import PROPERTY_KEY_RE
1110
from models_library.basic_types import IDStr
1211
from models_library.services_io import BaseServiceIOModel
12+
from models_library.services_types import ServicePortKey
1313
from pydantic import AnyUrl, Field, PrivateAttr, ValidationError, validator
1414
from pydantic.tools import parse_obj_as
1515
from servicelib.progress_bar import ProgressBarData
@@ -68,7 +68,7 @@ class SetKWargs:
6868

6969

7070
class Port(BaseServiceIOModel):
71-
key: str = Field(..., regex=PROPERTY_KEY_RE)
71+
key: ServicePortKey
7272
widget: dict[str, Any] | None = None
7373
default_value: DataItemValue | None = Field(None, alias="defaultValue")
7474

packages/simcore-sdk/src/simcore_sdk/node_ports_v2/ports_mapping.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
1-
import re
21
from collections.abc import ItemsView, Iterator, KeysView, ValuesView
32

4-
from models_library.basic_regex import PROPERTY_KEY_RE
5-
from pydantic import BaseModel, ConstrainedStr
3+
from models_library.services_types import ServicePortKey
4+
from pydantic import BaseModel
65

76
from ..node_ports_common.exceptions import UnboundPortError
87
from .port import Port
98

109

11-
class PortKey(ConstrainedStr):
12-
regex = re.compile(PROPERTY_KEY_RE)
13-
14-
1510
class BasePortsMapping(BaseModel):
16-
__root__: dict[PortKey, Port]
11+
__root__: dict[ServicePortKey, Port]
1712

18-
def __getitem__(self, key: int | PortKey) -> Port:
13+
def __getitem__(self, key: int | ServicePortKey) -> Port:
1914
if isinstance(key, int):
2015
if key < len(self.__root__):
2116
key = list(self.__root__.keys())[key]
@@ -24,13 +19,13 @@ def __getitem__(self, key: int | PortKey) -> Port:
2419
assert isinstance(key, str) # nosec
2520
return self.__root__[key]
2621

27-
def __iter__(self) -> Iterator[PortKey]: # type: ignore
22+
def __iter__(self) -> Iterator[ServicePortKey]: # type: ignore
2823
return iter(self.__root__)
2924

30-
def keys(self) -> KeysView[PortKey]:
25+
def keys(self) -> KeysView[ServicePortKey]:
3126
return self.__root__.keys()
3227

33-
def items(self) -> ItemsView[PortKey, Port]:
28+
def items(self) -> ItemsView[ServicePortKey, Port]:
3429
return self.__root__.items()
3530

3631
def values(self) -> ValuesView[Port]:

0 commit comments

Comments
 (0)