22import collections
33import logging
44from collections .abc import Awaitable , Callable , Coroutine , Generator
5- from typing import Any , Final , NoReturn , ParamSpec , TypeVar , cast , get_args
5+ from typing import Any , Final , NoReturn , ParamSpec , TypeVar , cast
66from uuid import uuid4
77
88import dask_gateway # type: ignore[import-untyped]
1111from common_library .json_serialization import json_dumps
1212from dask_task_models_library .container_tasks .io import (
1313 FileUrl ,
14- PortValue ,
1514 TaskInputData ,
1615 TaskOutputData ,
1716 TaskOutputDataSchema ,
6362
6463_PVType = _NPItemValue | None
6564
66- assert len (get_args (_PVType )) == len ( # nosec
67- get_args (PortValue )
68- ), "Types returned by port.get_value() -> _PVType MUST map one-to-one to PortValue. See compute_input_data"
69-
7065
7166def _get_port_validation_errors (port_key : str , err : ValidationError ) -> list [ErrorDict ]:
7267 errors = err .errors ()
@@ -104,7 +99,7 @@ def parse_dask_job_id(
10499 return (
105100 parts [0 ],
106101 parts [1 ],
107- UserID (parts [2 ][len ("userid_" ) :]),
102+ TypeAdapter ( UserID ). validate_python (parts [2 ][len ("userid_" ) :]),
108103 ProjectID (parts [3 ][len ("projectid_" ) :]),
109104 NodeID (parts [4 ][len ("nodeid_" ) :]),
110105 )
@@ -130,7 +125,7 @@ async def create_node_ports(
130125 return await node_ports_v2 .ports (
131126 user_id = user_id ,
132127 project_id = ProjectIDStr (f"{ project_id } " ),
133- node_uuid = NodeIDStr (f"{ node_id } " ),
128+ node_uuid = TypeAdapter ( NodeIDStr ). validate_python (f"{ node_id } " ),
134129 db_manager = db_manager ,
135130 )
136131 except ValidationError as err :
@@ -350,8 +345,8 @@ async def compute_task_envs(
350345 vendor_substituted_envs = await substitute_vendor_secrets_in_specs (
351346 app ,
352347 cast (dict [str , Any ], node_image .envs ),
353- service_key = ServiceKey (node_image .name ),
354- service_version = ServiceVersion (node_image .tag ),
348+ service_key = TypeAdapter ( ServiceKey ). validate_python (node_image .name ),
349+ service_version = TypeAdapter ( ServiceVersion ). validate_python (node_image .tag ),
355350 product_name = product_name ,
356351 )
357352 resolved_envs = await resolve_and_substitute_session_variables_in_specs (
0 commit comments