Skip to content

Commit 13243cc

Browse files
authored
[ml] Fix api view mypy errors (#34581)
* Revert change to acs_connection_id type * Address remaining type issues * Revert changes to irrelevant files * Add whitespace back * Remove unintentional change * Remove Optional type annotation from get() methods * Remove duplicate overloads * Fix circular import * Revert lost input/output overload types * Remove duplicate overloads for uri_folder * Use type:ignore to silence known incompatibilities
1 parent 059b833 commit 13243cc

File tree

15 files changed

+69
-82
lines changed

15 files changed

+69
-82
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import logging
1010
import os
1111
import re
12+
from enum import Enum
1213
from typing import Any, Dict, List, Optional, Tuple, Type, Union, cast
1314

1415
from marshmallow import INCLUDE, Schema
@@ -23,6 +24,7 @@
2324
)
2425
from azure.ai.ml.entities._job.job import Job
2526
from azure.ai.ml.entities._job.parallel.run_function import RunFunction
27+
from azure.ai.ml.entities._job.pipeline._io import NodeOutput
2628

2729
from ..._schema import PathAwareSchema
2830
from ..._utils.utils import is_data_binding_expression
@@ -31,7 +33,7 @@
3133
from .._component.component import Component
3234
from .._component.flow import FlowComponent
3335
from .._component.parallel_component import ParallelComponent
34-
from .._inputs_outputs import Output
36+
from .._inputs_outputs import Input, Output
3537
from .._job.job_resource_configuration import JobResourceConfiguration
3638
from .._job.parallel.parallel_job import ParallelJob
3739
from .._job.parallel.parallel_task import ParallelTask
@@ -108,7 +110,7 @@ def __init__(
108110
*,
109111
component: Union[ParallelComponent, str],
110112
compute: Optional[str] = None,
111-
inputs: Optional[Dict] = None,
113+
inputs: Optional[Dict[str, Union[NodeOutput, Input, str, bool, int, float, Enum]]] = None,
112114
outputs: Optional[Dict[str, Union[str, Output, "Output"]]] = None,
113115
retry_settings: Optional[Union[RetrySettings, Dict[str, str]]] = None,
114116
logging_level: Optional[str] = None,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,9 @@ def __setattr__(self, key: Any, value: Any) -> None:
427427
# only one of slack_amount and slack_factor can be specified but default value is 0.0.
428428
# Need to keep track of which one is null.
429429
if self.early_termination.slack_amount == 0.0:
430-
self.early_termination.slack_amount = None
430+
self.early_termination.slack_amount = None # type: ignore[assignment]
431431
if self.early_termination.slack_factor == 0.0:
432-
self.early_termination.slack_factor = None
432+
self.early_termination.slack_factor = None # type: ignore[assignment]
433433

434434
@property
435435
def early_termination(self) -> Optional[Union[str, EarlyTerminationPolicy]]:

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_datastore/azure_storage.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ class AzureFileDatastore(Datastore):
4545
:param properties: The asset property dictionary.
4646
:type properties: dict[str, str]
4747
:param credentials: Credentials to use for Azure ML workspace to connect to the storage.
48-
:type credentials: Union[AccountKeySection, SasSection]
48+
:type credentials: Union[~azure.ai.ml.entities.AccountKeyConfiguration,
49+
~azure.ai.ml.entities.SasTokenConfiguration]
4950
:param kwargs: A dictionary of additional configuration parameters.
5051
:type kwargs: dict
5152
"""
@@ -61,7 +62,7 @@ def __init__(
6162
endpoint: str = _get_storage_endpoint_from_metadata(),
6263
protocol: str = HTTPS,
6364
properties: Optional[Dict] = None,
64-
credentials: Any,
65+
credentials: Union[AccountKeyConfiguration, SasTokenConfiguration],
6566
**kwargs: Any
6667
):
6768
kwargs[TYPE] = DatastoreType.AZURE_FILE
@@ -97,7 +98,7 @@ def _from_rest_object(cls, datastore_resource: DatastoreData) -> "AzureFileDatas
9798
name=datastore_resource.name,
9899
id=datastore_resource.id,
99100
account_name=properties.account_name,
100-
credentials=from_rest_datastore_credentials(properties.credentials),
101+
credentials=from_rest_datastore_credentials(properties.credentials), # type: ignore[arg-type]
101102
endpoint=properties.endpoint,
102103
protocol=properties.protocol,
103104
file_share_name=properties.file_share_name,
@@ -260,7 +261,7 @@ def __init__(
260261
endpoint: str = _get_storage_endpoint_from_metadata(),
261262
protocol: str = HTTPS,
262263
properties: Optional[Dict] = None,
263-
credentials: Any = None,
264+
credentials: Optional[Union[AccountKeyConfiguration, SasTokenConfiguration]] = None,
264265
**kwargs: Any
265266
):
266267
kwargs[TYPE] = DatastoreType.AZURE_DATA_LAKE_GEN2
@@ -299,7 +300,7 @@ def _from_rest_object(cls, datastore_resource: DatastoreData) -> "AzureDataLakeG
299300
name=datastore_resource.name,
300301
id=datastore_resource.id,
301302
account_name=properties.account_name,
302-
credentials=from_rest_datastore_credentials(properties.credentials),
303+
credentials=from_rest_datastore_credentials(properties.credentials), # type: ignore[arg-type]
303304
endpoint=properties.endpoint,
304305
protocol=properties.protocol,
305306
filesystem=properties.filesystem,

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_inputs_outputs/external_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def __init__(
6767
query: Optional[str] = None,
6868
table_name: Optional[str] = None,
6969
stored_procedure: Optional[str] = None,
70-
stored_procedure_params: Optional[List] = None,
70+
stored_procedure_params: Optional[List[Dict]] = None,
7171
connection: Optional[str] = None,
7272
) -> None:
7373
# As an annotation, it is not allowed to initialize the name.

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_inputs_outputs/input.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,6 @@ def __init__(
8585
) -> None:
8686
""""""
8787

88-
@overload
89-
def __init__(
90-
self,
91-
*,
92-
type: Literal["uri_folder"] = "uri_folder",
93-
path: Optional[str] = None,
94-
mode: Optional[str] = None,
95-
optional: Optional[bool] = None,
96-
description: Optional[str] = None,
97-
**kwargs: Any,
98-
) -> None:
99-
""""""
100-
10188
@overload
10289
def __init__(
10390
self,

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_inputs_outputs/output.py

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,42 @@ def __init__(
3434

3535
@overload
3636
def __init__(
37+
self,
38+
type: Literal["uri_file"] = "uri_file",
39+
path: Optional[str] = None,
40+
mode: Optional[str] = None,
41+
description: Optional[str] = None,
42+
):
43+
"""Define a URI file output.
44+
45+
:keyword type: The type of the data output. Can only be set to 'uri_file'.
46+
:paramtype type: str
47+
:keyword path: The remote path where the output should be stored.
48+
:paramtype path: str
49+
:keyword mode: The access mode of the data output. Accepted values are
50+
* 'rw_mount': Read-write mount the data,
51+
* 'upload': Upload the data from the compute target,
52+
* 'direct': Pass in the URI as a string
53+
:paramtype mode: str
54+
:keyword description: The description of the output.
55+
:paramtype description: str
56+
:keyword name: The name to be used to register the output as a Data or Model asset. A name can be set without
57+
setting a version.
58+
:paramtype name: str
59+
:keyword version: The version used to register the output as a Data or Model asset. A version can be set only
60+
when name is set.
61+
:paramtype version: str
62+
"""
63+
64+
def __init__( # type: ignore[misc]
3765
self,
3866
*,
39-
type: Literal["uri_folder"] = "uri_folder",
67+
type: str = AssetTypes.URI_FOLDER,
4068
path: Optional[str] = None,
4169
mode: Optional[str] = None,
4270
description: Optional[str] = None,
71+
**kwargs: Any,
4372
) -> None:
44-
# pylint: disable=line-too-long
4573
"""Define an output.
4674
4775
:keyword type: The type of the data output. Accepted values are 'uri_folder', 'uri_file', 'mltable',
@@ -68,9 +96,8 @@ def __init__(
6896
:paramtype early_available: bool
6997
:keyword intellectual_property: Intellectual property associated with the output.
7098
It can be an instance of `IntellectualProperty` or a dictionary that will be used to create an instance.
71-
:paramtype intellectual_property: Union[~azure.ai.ml.entities._assets.intellectual_property.IntellectualProperty,
72-
73-
dict]
99+
:paramtype intellectual_property: Union[
100+
~azure.ai.ml.entities._assets.intellectual_property.IntellectualProperty, dict]
74101
75102
.. admonition:: Example:
76103
@@ -81,46 +108,6 @@ def __init__(
81108
:dedent: 8
82109
:caption: Creating a CommandJob with a folder output.
83110
"""
84-
85-
@overload
86-
def __init__(
87-
self,
88-
*,
89-
type: Literal["uri_file"] = "uri_file",
90-
path: Optional[str] = None,
91-
mode: Optional[str] = None,
92-
description: Optional[str] = None,
93-
):
94-
"""Define a URI file output.
95-
96-
:keyword type: The type of the data output. Can only be set to 'uri_file'.
97-
:paramtype type: str
98-
:keyword path: The remote path where the output should be stored.
99-
:paramtype path: str
100-
:keyword mode: The access mode of the data output. Accepted values are
101-
* 'rw_mount': Read-write mount the data,
102-
* 'upload': Upload the data from the compute target,
103-
* 'direct': Pass in the URI as a string
104-
:paramtype mode: str
105-
:keyword description: The description of the output.
106-
:paramtype description: str
107-
:keyword name: The name to be used to register the output as a Data or Model asset. A name can be set without
108-
setting a version.
109-
:paramtype name: str
110-
:keyword version: The version used to register the output as a Data or Model asset. A version can be set only
111-
when name is set.
112-
:paramtype version: str
113-
"""
114-
115-
def __init__(
116-
self,
117-
*,
118-
type: str = AssetTypes.URI_FOLDER,
119-
path: Optional[str] = None,
120-
mode: Optional[str] = None,
121-
description: Optional[str] = None,
122-
**kwargs: Any,
123-
) -> None:
124111
super(Output, self).__init__(type=type)
125112
# As an annotation, it is not allowed to initialize the _port_name.
126113
self._port_name = None

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_job/job.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def status(self) -> Optional[str]:
141141
return self._status
142142

143143
@property
144-
def log_files(self) -> Optional[Dict]:
144+
def log_files(self) -> Optional[Dict[str, str]]:
145145
"""Job output files.
146146
147147
:return: The dictionary of log names and URLs.
@@ -208,10 +208,10 @@ def _resolve_cls_and_type(cls, data: Dict, params_override: Optional[List[Dict]]
208208
from azure.ai.ml.entities._builders.command import Command
209209
from azure.ai.ml.entities._builders.spark import Spark
210210
from azure.ai.ml.entities._job.automl.automl_job import AutoMLJob
211+
from azure.ai.ml.entities._job.finetuning.finetuning_job import FineTuningJob
211212
from azure.ai.ml.entities._job.import_job import ImportJob
212213
from azure.ai.ml.entities._job.pipeline.pipeline_job import PipelineJob
213214
from azure.ai.ml.entities._job.sweep.sweep_job import SweepJob
214-
from azure.ai.ml.entities._job.finetuning.finetuning_job import FineTuningJob
215215

216216
job_type: Optional[Type["Job"]] = None
217217
type_in_override = find_type_in_override(params_override)
@@ -293,9 +293,9 @@ def _from_rest_object( # pylint: disable=too-many-return-statements
293293
from azure.ai.ml.entities._builders.spark import Spark
294294
from azure.ai.ml.entities._job.automl.automl_job import AutoMLJob
295295
from azure.ai.ml.entities._job.base_job import _BaseJob
296+
from azure.ai.ml.entities._job.finetuning.finetuning_job import FineTuningJob
296297
from azure.ai.ml.entities._job.import_job import ImportJob
297298
from azure.ai.ml.entities._job.sweep.sweep_job import SweepJob
298-
from azure.ai.ml.entities._job.finetuning.finetuning_job import FineTuningJob
299299

300300
try:
301301
if isinstance(obj, Run):

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_job/parallel/parallel_job.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def _to_node(self, context: Optional[Dict] = None, **kwargs: Any) -> "Parallel":
200200
component=component,
201201
compute=self.compute,
202202
# Need to supply the inputs with double curly.
203-
inputs=self.inputs,
203+
inputs=self.inputs, # type: ignore[arg-type]
204204
outputs=self.outputs, # type: ignore[arg-type]
205205
mini_batch_size=self.mini_batch_size,
206206
partition_keys=self.partition_keys,

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_job/sweep/early_termination_policy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ def __init__(
7777
*,
7878
delay_evaluation: int = 0,
7979
evaluation_interval: int = 0,
80-
slack_amount: Optional[float] = 0,
81-
slack_factor: Optional[float] = 0,
80+
slack_amount: float = 0,
81+
slack_factor: float = 0,
8282
) -> None:
8383
super().__init__(delay_evaluation=delay_evaluation, evaluation_interval=evaluation_interval)
8484
self.type = EarlyTerminationPolicyType.BANDIT.lower()

sdk/ml/azure-ai-ml/azure/ai/ml/operations/_feature_set_operations.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def _get(self, name: str, version: Optional[str] = None, **kwargs: Dict) -> Feat
125125

126126
@distributed_trace
127127
@monitor_with_activity(ops_logger, "FeatureSet.Get", ActivityType.PUBLICAPI)
128-
def get(self, name: str, version: str, **kwargs: Dict) -> Optional[FeatureSet]: # type: ignore
128+
def get(self, name: str, version: str, **kwargs: Dict) -> FeatureSet: # type: ignore
129129
"""Get the specified FeatureSet asset.
130130
131131
:param name: Name of FeatureSet asset.
@@ -134,6 +134,8 @@ def get(self, name: str, version: str, **kwargs: Dict) -> Optional[FeatureSet]:
134134
:type version: str
135135
:raises ~azure.ai.ml.exceptions.ValidationException: Raised if FeatureSet cannot be successfully
136136
identified and retrieved. Details will be provided in the error message.
137+
:raises ~azure.core.exceptions.HttpResponseError: Raised if the corresponding name and version cannot be
138+
retrieved from the service.
137139
:return: FeatureSet asset object.
138140
:rtype: ~azure.ai.ml.entities.FeatureSet
139141
"""

0 commit comments

Comments
 (0)