Skip to content

Commit 4d57f2f

Browse files
ZubaeyrMSFTZubairuddin Mohammed
andauthored
next-mypy fixes azure-ai-ml sdk (#44132)
* next-mypy fixes for automl in azure-ai-ml sdk * remainging next mypy issues fix * minimizing the changes * resolving type issue with control flow node file * minimizing the mypy changes * minimizing the mypy changes * minimizing the mypy changes * minimizing the mypy changes --------- Co-authored-by: Zubairuddin Mohammed <[email protected]>
1 parent 898eadd commit 4d57f2f

38 files changed

+148
-102
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ def jars(self) -> Optional[List[str]]:
140140
return self._jars
141141

142142
@jars.setter
143-
def jars(self, value: Union[str, List[str]]):
143+
def jars(self, value: Optional[Union[str, List[str]]]):
144144
"""Set the jars of the component.
145145
146146
:param value: The jars of the component.
147-
:type value: Union[str, List[str]]
147+
:type value: Optional[Union[str, List[str]]]
148148
:return: No return
149149
:rtype: None
150150
"""

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def path(self) -> Optional[Union[Path, str, PathLike]]:
120120
return self._path
121121

122122
@path.setter
123-
def path(self, value: str) -> None:
123+
def path(self, value: Optional[Union[str, PathLike]]) -> None:
124124
# Call the parent setter to resolve the path with base_path if it was a local path
125125
# TODO: Bug Item number: 2883424
126126
super(Data, type(self)).path.fset(self, value) # type: ignore

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ def version(self) -> Optional[str]:
8585
return self._version
8686

8787
@version.setter
88-
def version(self, value: str) -> None:
88+
def version(self, value: Optional[str]) -> None:
8989
"""Sets the asset version.
9090
9191
:param value: The asset version.
92-
:type value: str
92+
:type value: Optional[str]
9393
:raises ValidationException: Raised if value is not a string.
9494
"""
9595
if value:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def _from_container_rest_object(cls, env_container_rest_object: EnvironmentConta
284284

285285
# Setting version to None since if version is not provided it is defaulted to "1".
286286
# This should go away once container concept is finalized.
287-
env.version = None
287+
env.version = None # type: ignore[assignment]
288288
return env
289289

290290
def _to_arm_resource_param(self, **kwargs: Any) -> Dict: # pylint: disable=unused-argument
@@ -404,7 +404,7 @@ def _localize(self, base_path: str) -> None:
404404
self._creation_context = None
405405
self._base_path = base_path
406406
if self._is_anonymous:
407-
self.name, self.version = None, None
407+
self.name, self.version = None, None # type: ignore[assignment]
408408

409409

410410
# TODO: Remove _DockerBuild and _DockerConfiguration classes once local endpoint moves to using updated env

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,11 @@ def name(self) -> Optional[str]:
205205
return self._name
206206

207207
@name.setter
208-
def name(self, value: str) -> None:
208+
def name(self, value: Optional[str]) -> None:
209209
"""Set the name of the node.
210210
211211
:param value: The name to set for the node.
212-
:type value: str
212+
:type value: Optional[str]
213213
:return: None
214214
"""
215215
# when name is not lower case, lower it to make sure it's a valid node name

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,22 @@ def distribution(
260260
@distribution.setter
261261
def distribution(
262262
self,
263-
value: Union[Dict, PyTorchDistribution, TensorFlowDistribution, MpiDistribution, RayDistribution],
263+
value: Optional[
264+
Union[
265+
Dict,
266+
PyTorchDistribution,
267+
TensorFlowDistribution,
268+
MpiDistribution,
269+
RayDistribution,
270+
DistributionConfiguration,
271+
]
272+
],
264273
) -> None:
265274
"""Sets the configuration for the distributed command component or job.
266275
267276
:param value: The configuration for distributed jobs.
268-
:type value: Union[dict, ~azure.ai.ml.PyTorchDistribution, ~azure.ai.ml.MpiDistribution,
269-
~azure.ai.ml.TensorFlowDistribution, ~azure.ai.ml.RayDistribution]
277+
:type value: Optional[Union[dict, ~azure.ai.ml.PyTorchDistribution, ~azure.ai.ml.MpiDistribution,
278+
~azure.ai.ml.TensorFlowDistribution, ~azure.ai.ml.RayDistribution]]
270279
"""
271280
if isinstance(value, dict):
272281
dist_schema = UnionField(
@@ -309,11 +318,11 @@ def queue_settings(self) -> Optional[QueueSettings]:
309318
return self._queue_settings
310319

311320
@queue_settings.setter
312-
def queue_settings(self, value: Union[Dict, QueueSettings]) -> None:
321+
def queue_settings(self, value: Optional[Union[Dict, QueueSettings]]) -> None:
313322
"""Sets the queue settings for the command component or job.
314323
315324
:param value: The queue settings for the command component or job.
316-
:type value: Union[dict, ~azure.ai.ml.entities.QueueSettings]
325+
:type value: Optional[Union[dict, ~azure.ai.ml.entities.QueueSettings]]
317326
"""
318327
if isinstance(value, dict):
319328
value = QueueSettings(**value)
@@ -373,7 +382,7 @@ def services(
373382
@services.setter
374383
def services(
375384
self,
376-
value: Dict,
385+
value: Optional[Dict],
377386
) -> None:
378387
"""Sets the interactive services for the node.
379388

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,5 +166,7 @@ def _from_rest_object(cls, obj: dict, pipeline_jobs: dict) -> "LoopNode":
166166
from azure.ai.ml.entities._job.pipeline._load_component import pipeline_node_factory
167167

168168
node_type = obj.get(CommonYamlFields.TYPE, None)
169-
load_from_rest_obj_func = pipeline_node_factory.get_load_from_rest_object_func(_type=node_type)
169+
load_from_rest_obj_func = pipeline_node_factory.get_load_from_rest_object_func(
170+
_type=node_type # type: ignore[arg-type]
171+
)
170172
return load_from_rest_obj_func(obj, pipeline_jobs) # type: ignore

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ def sink(self) -> Optional[Union[Dict, Database, FileSystem]]:
493493
return self._sink
494494

495495
@sink.setter
496-
def sink(self, value: Union[Dict, Database, FileSystem]) -> None:
496+
def sink(self, value: Optional[Union[Dict, Database, FileSystem]]) -> None:
497497
self._sink = _build_source_sink(value)
498498

499499
@classmethod

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,12 @@ def resources(self) -> Optional[JobResourceConfiguration]:
252252
return self._resources
253253

254254
@resources.setter
255-
def resources(self, value: Union[JobResourceConfiguration, Dict]) -> None:
255+
def resources(self, value: Optional[Union[JobResourceConfiguration, Dict]]) -> None:
256256
"""Set the resource configuration for the parallel job.
257257
258258
:param value: The resource configuration for the parallel job.
259-
:type value: ~azure.ai.ml.entities._job.job_resource_configuration.JobResourceConfiguration or dict
259+
:type value: Optional[Union[
260+
~azure.ai.ml.entities._job.job_resource_configuration.JobResourceConfiguration, dict]]
260261
"""
261262
if isinstance(value, dict):
262263
value = JobResourceConfiguration(**value)
@@ -316,11 +317,11 @@ def task(self) -> Optional[ParallelTask]:
316317
return self._task # type: ignore
317318

318319
@task.setter
319-
def task(self, value: Union[ParallelTask, Dict]) -> None:
320+
def task(self, value: Optional[Union[ParallelTask, Dict]]) -> None:
320321
"""Set the parallel task.
321322
322323
:param value: The parallel task.
323-
:type value: ~azure.ai.ml.entities._job.parallel.parallel_task.ParallelTask or dict
324+
:type value: Optional[Union[~azure.ai.ml.entities._job.parallel.parallel_task.ParallelTask, dict]]
324325
"""
325326
# base path should be reset if task is set via sdk
326327
self._base_path: Optional[Union[str, os.PathLike]] = None
@@ -360,16 +361,18 @@ def set_resources(
360361
if self.resources is None:
361362
self.resources = JobResourceConfiguration()
362363

364+
# Use local variable for type narrowing
365+
resources = self.resources
363366
if instance_type is not None:
364-
self.resources.instance_type = instance_type
367+
resources.instance_type = instance_type
365368
if instance_count is not None:
366-
self.resources.instance_count = instance_count
369+
resources.instance_count = instance_count
367370
if properties is not None:
368-
self.resources.properties = properties
371+
resources.properties = properties
369372
if docker_args is not None:
370-
self.resources.docker_args = docker_args
373+
resources.docker_args = docker_args
371374
if shm_size is not None:
372-
self.resources.shm_size = shm_size
375+
resources.shm_size = shm_size
373376

374377
# Save the resources to internal component as well, otherwise calling sweep() will loose the settings
375378
if isinstance(self.component, Component):

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ def settings(self) -> Optional[PipelineJobSettings]:
103103
return self._settings
104104

105105
@settings.setter
106-
def settings(self, value: Union[PipelineJobSettings, Dict]) -> None:
106+
def settings(self, value: Optional[Union[PipelineJobSettings, Dict]]) -> None:
107107
"""Set the settings of the pipeline.
108108
109109
:param value: The settings of the pipeline.
110-
:type value: Union[~azure.ai.ml.entities.PipelineJobSettings, dict]
110+
:type value: Optional[Union[~azure.ai.ml.entities.PipelineJobSettings, dict]]
111111
:raises TypeError: If the value is not an instance of PipelineJobSettings or a dict.
112112
"""
113113
if value is not None:

0 commit comments

Comments
 (0)