Skip to content

Commit 3ea3625

Browse files
Fix mypy errors in ApiView (#34477)
* fix mypy errors * fix mypy errors - 2 * fix definition.py * fix mypy errors - 3 * fix mypy errors - 4 * fix mypy errors - 5 * fix mypy errors - 6 * fix mypy errors in comments * fix comments issues
1 parent 4d8b372 commit 3ea3625

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+276
-189
lines changed

sdk/ml/azure-ai-ml/azure/ai/ml/_internal/entities/component.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def __init__(
115115
tags=tags,
116116
properties=properties,
117117
display_name=display_name,
118-
is_deterministic=is_deterministic,
118+
is_deterministic=is_deterministic, # type: ignore[arg-type]
119119
inputs=inputs,
120120
outputs=outputs,
121121
yaml_str=yaml_str,

sdk/ml/azure-ai-ml/azure/ai/ml/_local_endpoints/validators/code_validator.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,18 @@ def _local_scoring_script_is_valid(deployment: OnlineDeployment):
8888
def _code_configuration_contains_cloud_artifacts(deployment: OnlineDeployment):
8989
# If the deployment.code_configuration.code is a string, then it is the cloud code artifact name or full arm ID
9090

91-
return isinstance(deployment.code_configuration.code, str) and (
92-
is_url(deployment.code_configuration.code) or deployment.code_configuration.code.startswith(ARM_ID_PREFIX)
91+
return isinstance(deployment.code_configuration.code, str) and ( # type: ignore[union-attr]
92+
is_url(deployment.code_configuration.code) # type: ignore[union-attr]
93+
or deployment.code_configuration.code.startswith(ARM_ID_PREFIX) # type: ignore[union-attr]
9394
)
9495

9596

9697
def _get_local_code_configuration_artifacts(
9798
deployment: OnlineDeployment,
9899
) -> Path:
99-
return Path(deployment._base_path, deployment.code_configuration.code).resolve()
100+
return Path(
101+
deployment._base_path, deployment.code_configuration.code # type: ignore[union-attr, arg-type]
102+
).resolve()
100103

101104

102105
def _get_cloud_code_configuration_artifacts(code: str, code_operations: CodeOperations, download_path: str) -> str:

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_assets/_artifacts/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def __init__(
7676
type: Optional[str] = None, # pylint: disable=redefined-builtin
7777
path: Optional[Union[str, PathLike]] = None,
7878
utc_time_created: Optional[str] = None,
79-
flavors: Optional[Dict] = None,
79+
flavors: Optional[Dict[str, Dict[str, Any]]] = None,
8080
description: Optional[str] = None,
8181
tags: Optional[Dict] = None,
8282
properties: Optional[Dict] = None,

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_assets/environment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def __init__(
124124
**kwargs: Any,
125125
):
126126
self._arm_type: str = ""
127-
self.latest_version: str = ""
127+
self.latest_version: str = "" # type: ignore[assignment]
128128
self.image: Optional[str] = None
129129
inference_config = kwargs.pop("inference_config", None)
130130
os_type = kwargs.pop("os_type", None)

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_builders/command.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
# ---------------------------------------------------------
22
# Copyright (c) Microsoft Corporation. All rights reserved.
33
# ---------------------------------------------------------
4-
54
# pylint: disable=protected-access
6-
75
import copy
86
import logging
97
import os
@@ -170,7 +168,9 @@ def __init__(
170168
environment: Optional[Union[Environment, str]] = None,
171169
environment_variables: Optional[Dict] = None,
172170
resources: Optional[JobResourceConfiguration] = None,
173-
services: Optional[Dict] = None,
171+
services: Optional[
172+
Dict[str, Union[JobService, JupyterLabJobService, SshJobService, TensorBoardJobService, VsCodeJobService]]
173+
] = None,
174174
queue_settings: Optional[QueueSettings] = None,
175175
**kwargs: Any,
176176
) -> None:
@@ -205,7 +205,7 @@ def __init__(
205205
self.queue_settings = queue_settings
206206

207207
if isinstance(self.component, CommandComponent):
208-
self.resources = self.resources or self.component.resources
208+
self.resources = self.resources or self.component.resources # type: ignore[assignment]
209209
self.distribution = self.distribution or self.component.distribution
210210

211211
self._swept: bool = False
@@ -277,12 +277,12 @@ def distribution(
277277
self._distribution = value
278278

279279
@property
280-
def resources(self) -> Any:
280+
def resources(self) -> JobResourceConfiguration:
281281
"""The compute resource configuration for the command component or job.
282282
283283
:rtype: ~azure.ai.ml.entities.JobResourceConfiguration
284284
"""
285-
return self._resources
285+
return cast(JobResourceConfiguration, self._resources)
286286

287287
@resources.setter
288288
def resources(self, value: Union[Dict, JobResourceConfiguration]) -> None:
@@ -381,10 +381,10 @@ def services(
381381
~azure.ai.ml.entities.SshJobService, ~azure.ai.ml.entities.TensorBoardJobService,
382382
~azure.ai.ml.entities.VsCodeJobService]]
383383
"""
384-
self._services = _resolve_job_services(value)
384+
self._services = _resolve_job_services(value) # type: ignore[assignment]
385385

386386
@property
387-
def component(self) -> Any:
387+
def component(self) -> Union[str, CommandComponent]:
388388
"""The ID or instance of the command component or job to be run for the step.
389389
390390
:return: The ID or instance of the command component or job to be run for the step.
@@ -855,7 +855,9 @@ def _load_from_rest_job(cls, obj: JobBase) -> "Command":
855855
outputs=from_rest_data_outputs(rest_command_job.outputs),
856856
)
857857
command_job._id = obj.id
858-
command_job.resources = JobResourceConfiguration._from_rest_object(rest_command_job.resources)
858+
command_job.resources = cast(
859+
JobResourceConfiguration, JobResourceConfiguration._from_rest_object(rest_command_job.resources)
860+
)
859861
command_job.limits = CommandJobLimits._from_rest_object(rest_command_job.limits)
860862
command_job.queue_settings = QueueSettings._from_rest_object(rest_command_job.queue_settings)
861863
if isinstance(command_job.component, CommandComponent):
@@ -939,7 +941,7 @@ def __call__(self, *args: Any, **kwargs: Any) -> "Command":
939941

940942

941943
@overload
942-
def _resolve_job_services(services: None) -> None:
944+
def _resolve_job_services(services: Optional[Dict]):
943945
...
944946

945947

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_builders/parallel.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def __init__(
110110
compute: Optional[str] = None,
111111
inputs: Optional[Dict] = None,
112112
outputs: Optional[Dict[str, Union[str, Output, "Output"]]] = None,
113-
retry_settings: Optional[Union[RetrySettings, Dict]] = None,
113+
retry_settings: Optional[Union[RetrySettings, Dict[str, str]]] = None,
114114
logging_level: Optional[str] = None,
115115
max_concurrency_per_instance: Optional[int] = None,
116116
error_threshold: Optional[int] = None,
@@ -132,7 +132,8 @@ def __init__(
132132

133133
if isinstance(component, FlowComponent):
134134
# make input definition fit actual inputs for flow component
135-
with component._inputs._fit_inputs(inputs): # pylint: disable=protected-access
135+
# pylint: disable=protected-access
136+
with component._inputs._fit_inputs(inputs): # type: ignore[attr-defined]
136137
BaseNode.__init__(
137138
self,
138139
type=NodeType.PARALLEL,

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_builders/parallel_func.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
ManagedIdentityConfiguration,
1212
UserIdentityConfiguration,
1313
)
14-
from azure.ai.ml.entities._job.parallel.retry_settings import RetrySettings
14+
from azure.ai.ml.entities._deployment.deployment_settings import BatchRetrySettings
1515
from azure.ai.ml.entities._job.parallel.run_function import RunFunction
1616

1717
from .command_func import _parse_input, _parse_inputs_outputs, _parse_output
@@ -27,7 +27,7 @@ def parallel_run_function(
2727
display_name: Optional[str] = None,
2828
experiment_name: Optional[str] = None,
2929
compute: Optional[str] = None,
30-
retry_settings: Optional[RetrySettings] = None,
30+
retry_settings: Optional[BatchRetrySettings] = None,
3131
environment_variables: Optional[Dict] = None,
3232
logging_level: Optional[str] = None,
3333
max_concurrency_per_instance: Optional[int] = None,
@@ -215,7 +215,7 @@ def parallel_run_function(
215215
description=description,
216216
inputs=component_inputs,
217217
outputs=component_outputs,
218-
retry_settings=retry_settings,
218+
retry_settings=retry_settings, # type: ignore[arg-type]
219219
logging_level=logging_level,
220220
max_concurrency_per_instance=max_concurrency_per_instance,
221221
error_threshold=error_threshold,
@@ -238,7 +238,7 @@ def parallel_run_function(
238238
description=description,
239239
inputs=component_inputs,
240240
outputs=component_outputs,
241-
retry_settings=retry_settings,
241+
retry_settings=retry_settings, # type: ignore[arg-type]
242242
logging_level=logging_level,
243243
max_concurrency_per_instance=max_concurrency_per_instance,
244244
error_threshold=error_threshold,
@@ -266,7 +266,7 @@ def parallel_run_function(
266266
outputs=job_outputs,
267267
identity=identity,
268268
environment_variables=environment_variables,
269-
retry_settings=retry_settings,
269+
retry_settings=retry_settings, # type: ignore[arg-type]
270270
logging_level=logging_level,
271271
max_concurrency_per_instance=max_concurrency_per_instance,
272272
error_threshold=error_threshold,

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_builders/sweep.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,14 @@ def __init__(
140140
early_termination: Optional[
141141
Union[BanditPolicy, MedianStoppingPolicy, TruncationSelectionPolicy, EarlyTerminationPolicy, str]
142142
] = None,
143-
search_space: Optional[Dict] = None,
143+
search_space: Optional[
144+
Dict[
145+
str,
146+
Union[
147+
Choice, LogNormal, LogUniform, Normal, QLogNormal, QLogUniform, QNormal, QUniform, Randint, Uniform
148+
],
149+
]
150+
] = None,
144151
inputs: Optional[Dict[str, Union[Input, str, bool, int, float]]] = None,
145152
outputs: Optional[Dict[str, Union[str, Output]]] = None,
146153
identity: Optional[
@@ -191,7 +198,12 @@ def trial(self) -> CommandComponent:
191198
@property
192199
def search_space(
193200
self,
194-
) -> Optional[Dict]:
201+
) -> Optional[
202+
Dict[
203+
str,
204+
Union[Choice, LogNormal, LogUniform, Normal, QLogNormal, QLogUniform, QNormal, QUniform, Randint, Uniform],
205+
]
206+
]:
195207
"""Dictionary of the hyperparameter search space.
196208
197209
Each key is the name of a hyperparameter and its value is the parameter expression.
@@ -210,7 +222,7 @@ def search_space(self, values: Dict[str, Dict[str, Union[str, int, float, dict]]
210222
:param values: The search space to set.
211223
:type values: Dict[str, Dict[str, Union[str, int, float, dict]]]
212224
"""
213-
search_space = {}
225+
search_space: Dict = {}
214226
for name, value in values.items():
215227
# If value is a SearchSpace object, directly pass it to job.search_space[name]
216228
search_space[name] = self._value_type_to_class(value) if isinstance(value, dict) else value
@@ -341,7 +353,7 @@ def _to_job(self) -> SweepJob:
341353
sampling_algorithm=self.sampling_algorithm,
342354
search_space=self.search_space,
343355
limits=self.limits,
344-
early_termination=self.early_termination,
356+
early_termination=self.early_termination, # type: ignore[arg-type]
345357
objective=self.objective,
346358
inputs=self._job_inputs,
347359
outputs=self._job_outputs,
@@ -420,7 +432,7 @@ def __setattr__(self, key: Any, value: Any) -> None:
420432
self.early_termination.slack_factor = None
421433

422434
@property
423-
def early_termination(self) -> Optional[EarlyTerminationPolicy]:
435+
def early_termination(self) -> Optional[Union[str, EarlyTerminationPolicy]]:
424436
"""The early termination policy for the sweep job.
425437
426438
:rtype: Union[str, ~azure.ai.ml.sweep.BanditPolicy, ~azure.ai.ml.sweep.MedianStoppingPolicy,
@@ -429,7 +441,7 @@ def early_termination(self) -> Optional[EarlyTerminationPolicy]:
429441
return self._early_termination
430442

431443
@early_termination.setter
432-
def early_termination(self, value: Optional[EarlyTerminationPolicy]) -> None:
444+
def early_termination(self, value: Optional[Union[str, EarlyTerminationPolicy]]) -> None:
433445
"""Sets the early termination policy for the sweep job.
434446
435447
:param value: The early termination policy for the sweep job.
@@ -439,4 +451,4 @@ def early_termination(self, value: Optional[EarlyTerminationPolicy]) -> None:
439451
if isinstance(value, dict):
440452
early_termination_schema = EarlyTerminationField()
441453
value = early_termination_schema._deserialize(value=value, attr=None, data=None)
442-
self._early_termination = value
454+
self._early_termination = value # type: ignore[assignment]

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_component/command_component.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def __init__(
113113
DistributionConfiguration,
114114
]
115115
] = None,
116-
resources: Optional[Union[Dict, JobResourceConfiguration]] = None,
116+
resources: Optional[JobResourceConfiguration] = None,
117117
inputs: Optional[Dict] = None,
118118
outputs: Optional[Dict] = None,
119119
instance_count: Optional[int] = None, # promoted property from resources.instance_count
@@ -150,7 +150,7 @@ def __init__(
150150
self.code = code
151151
self.environment_variables = environment_variables
152152
self.environment = environment
153-
self.resources = resources
153+
self.resources = resources # type: ignore[assignment]
154154
self.distribution = distribution
155155

156156
# check mutual exclusivity of promoted properties

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_component/component.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def __init__(
101101
tags: Optional[Dict] = None,
102102
properties: Optional[Dict] = None,
103103
display_name: Optional[str] = None,
104-
is_deterministic: Optional[bool] = True,
104+
is_deterministic: bool = True,
105105
inputs: Optional[Dict] = None,
106106
outputs: Optional[Dict] = None,
107107
yaml_str: Optional[str] = None,
@@ -423,7 +423,7 @@ def _from_container_rest_object(cls, component_container_rest_object: ComponentC
423423
properties=component_container_details.properties,
424424
type=NodeType._CONTAINER,
425425
# Set this field to None as it hold a default True in init.
426-
is_deterministic=None,
426+
is_deterministic=None, # type: ignore[arg-type]
427427
)
428428
component.latest_version = component_container_details.latest_version
429429
return component

0 commit comments

Comments
 (0)