Skip to content

Commit 22d2c6d

Browse files
Azure#37999 - Typing fix for mypy version 1.13 (Azure#39093)
* mypy 1.13 fixes * mypy 1.13 fixes 2nd iteration * mypy 1.13 fixes 3nd iteration * mypy / black, comment fixes * next-mypy - pylint / black fixes
1 parent 7af4a4d commit 22d2c6d

File tree

14 files changed

+45
-37
lines changed

14 files changed

+45
-37
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def __init__(
1717
name: str,
1818
version: str,
1919
relative_path: str,
20-
datastore_arm_id: str,
20+
datastore_arm_id: Optional[str],
2121
container_name: str,
2222
storage_account_url: Optional[str] = None,
2323
is_file: Optional[bool] = None,

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
@@ -231,7 +231,7 @@ def _update_path(self, asset_artifact: ArtifactStorageInfo) -> None:
231231
if not asset_artifact.datastore_arm_id and asset_artifact.full_storage_path:
232232
self.path = asset_artifact.full_storage_path
233233
else:
234-
groups = re.search(regex, asset_artifact.datastore_arm_id)
234+
groups = re.search(regex, asset_artifact.datastore_arm_id) # type: ignore
235235
if groups:
236236
datastore_name = groups.group(1)
237237
self.path = SHORT_URI_FORMAT.format(datastore_name, asset_artifact.relative_path)

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_compute/_image_metadata.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# ---------------------------------------------------------
22
# Copyright (c) Microsoft Corporation. All rights reserved.
33
# ---------------------------------------------------------
4+
from typing import Optional
45

56

67
class ImageMetadata:
@@ -24,14 +25,18 @@ class ImageMetadata:
2425
"""
2526

2627
def __init__(
27-
self, *, is_latest_os_image_version: bool, current_image_version: str, latest_image_version: str
28+
self,
29+
*,
30+
is_latest_os_image_version: Optional[bool],
31+
current_image_version: Optional[str],
32+
latest_image_version: Optional[str]
2833
) -> None:
2934
self._is_latest_os_image_version = is_latest_os_image_version
3035
self._current_image_version = current_image_version
3136
self._latest_image_version = latest_image_version
3237

3338
@property
34-
def is_latest_os_image_version(self) -> bool:
39+
def is_latest_os_image_version(self) -> Optional[bool]:
3540
"""Whether or not a compute instance is running on the latest OS image version.
3641
3742
:return: Boolean indicating if the compute instance is running the latest OS image version.
@@ -40,7 +45,7 @@ def is_latest_os_image_version(self) -> bool:
4045
return self._is_latest_os_image_version
4146

4247
@property
43-
def current_image_version(self) -> str:
48+
def current_image_version(self) -> Optional[str]:
4449
"""The current OS image version number.
4550
4651
:return: The current OS image version number.
@@ -49,7 +54,7 @@ def current_image_version(self) -> str:
4954
return self._current_image_version
5055

5156
@property
52-
def latest_image_version(self) -> str:
57+
def latest_image_version(self) -> Optional[str]:
5358
"""The latest OS image version number.
5459
5560
:return: The latest OS image version number.

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_compute/compute.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def _from_rest_object(cls, obj: ComputeResource) -> "Compute":
123123

124124
class_type = cast(
125125
Optional[Union[AmlCompute, ComputeInstance, VirtualMachineCompute, KubernetesCompute, SynapseSparkCompute]],
126-
mapping.get(compute_type, None),
126+
mapping.get(compute_type, None), # type: ignore
127127
)
128128
if class_type:
129129
return class_type._load_from_rest(obj)

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_compute/virtual_machine_compute.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ class VirtualMachineSshSettings:
4545
def __init__(
4646
self,
4747
*,
48-
admin_username: str,
48+
admin_username: Optional[str],
4949
admin_password: Optional[str] = None,
50-
ssh_port: int = 22,
50+
ssh_port: Optional[int] = 22,
5151
ssh_private_key_file: Optional[str] = None,
5252
) -> None:
5353
self.admin_username = admin_username

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_credentials.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class AccountKeyConfiguration(RestTranslatableMixin, DictMixin):
116116
def __init__(
117117
self,
118118
*,
119-
account_key: str,
119+
account_key: Optional[str],
120120
) -> None:
121121
self.type = camel_to_snake(CredentialsType.ACCOUNT_KEY)
122122
self.account_key = account_key
@@ -157,7 +157,7 @@ class SasTokenConfiguration(RestTranslatableMixin, DictMixin):
157157
def __init__(
158158
self,
159159
*,
160-
sas_token: str,
160+
sas_token: Optional[str],
161161
) -> None:
162162
super().__init__()
163163
self.type = camel_to_snake(CredentialsType.SAS)
@@ -209,7 +209,7 @@ class PatTokenConfiguration(RestTranslatableMixin, DictMixin):
209209
:caption: Configuring a personal access token configuration for a WorkspaceConnection.
210210
"""
211211

212-
def __init__(self, *, pat: str) -> None:
212+
def __init__(self, *, pat: Optional[str]) -> None:
213213
super().__init__()
214214
self.type = camel_to_snake(ConnectionAuthType.PAT)
215215
self.pat = pat
@@ -245,8 +245,8 @@ class UsernamePasswordConfiguration(RestTranslatableMixin, DictMixin):
245245
def __init__(
246246
self,
247247
*,
248-
username: str,
249-
password: str,
248+
username: Optional[str],
249+
password: Optional[str],
250250
) -> None:
251251
super().__init__()
252252
self.type = camel_to_snake(ConnectionAuthType.USERNAME_PASSWORD)
@@ -316,8 +316,8 @@ class ServicePrincipalConfiguration(BaseTenantCredentials):
316316
def __init__(
317317
self,
318318
*,
319-
client_secret: str,
320-
**kwargs: str,
319+
client_secret: Optional[str],
320+
**kwargs: Any,
321321
) -> None:
322322
super().__init__(**kwargs)
323323
self.type = camel_to_snake(CredentialsType.SERVICE_PRINCIPAL)
@@ -894,8 +894,8 @@ class AccessKeyConfiguration(RestTranslatableMixin, DictMixin):
894894
def __init__(
895895
self,
896896
*,
897-
access_key_id: str,
898-
secret_access_key: str,
897+
access_key_id: Optional[str],
898+
secret_access_key: Optional[str],
899899
) -> None:
900900
super().__init__()
901901
self.type = camel_to_snake(ConnectionAuthType.ACCESS_KEY)
@@ -936,7 +936,7 @@ class ApiKeyConfiguration(RestTranslatableMixin, DictMixin):
936936
def __init__(
937937
self,
938938
*,
939-
key: str,
939+
key: Optional[str],
940940
):
941941
super().__init__()
942942
self.type = camel_to_snake(ConnectionAuthType.API_KEY)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# ---------------------------------------------------------
44

55
from base64 import b64encode
6-
from typing import Any
6+
from typing import Any, Optional
77

88
from azure.ai.ml._restclient.v2023_04_01_preview import models as model_preview
99
from azure.ai.ml._utils._experimental import experimental
@@ -28,7 +28,7 @@ def __init__(
2828
kerberos_realm: str,
2929
kerberos_kdc_address: str,
3030
kerberos_principal: str,
31-
kerberos_keytab: str,
31+
kerberos_keytab: Optional[str],
3232
**kwargs: Any,
3333
):
3434
super().__init__(
@@ -84,7 +84,7 @@ def __init__(
8484
kerberos_realm: str,
8585
kerberos_kdc_address: str,
8686
kerberos_principal: str,
87-
kerberos_password: str,
87+
kerberos_password: Optional[str],
8888
**kwargs: Any,
8989
):
9090
super().__init__(

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_job/finetuning/finetuning_vertical.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def __init__(
2626
*,
2727
task: str,
2828
model: Input,
29-
model_provider: str,
29+
model_provider: Optional[str],
3030
training_data: Input,
3131
validation_data: Optional[Input] = None,
3232
**kwargs: Any,
@@ -93,7 +93,7 @@ def model(self, value: Input) -> None:
9393
)
9494

9595
@property
96-
def model_provider(self) -> str:
96+
def model_provider(self) -> Optional[str]:
9797
"""The model provider.
9898
:return: The model provider.
9999
:rtype: str

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_job/pipeline/_io/base.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ def __init__(
124124
)
125125
# TODO: remove this
126126
self._attribute_map: Dict = {}
127-
self._name: str = ""
128-
self._version: str = ""
127+
self._name: Optional[str] = ""
128+
self._version: Optional[str] = ""
129129
super(InputOutputBase, self).__init__(**kwargs)
130130

131131
@abstractmethod
@@ -510,8 +510,8 @@ def __init__(
510510
super().__init__(meta=meta, data=data, **kwargs)
511511
self._port_name = port_name
512512
self._owner = owner
513-
self._name: str = self._data.name if isinstance(self._data, Output) else None
514-
self._version: str = self._data.version if isinstance(self._data, Output) else None
513+
self._name: Optional[str] = self._data.name if isinstance(self._data, Output) else None
514+
self._version: Optional[str] = self._data.version if isinstance(self._data, Output) else None
515515

516516
self._assert_name_and_version()
517517

@@ -528,7 +528,7 @@ def port_name(self) -> str:
528528
return self._port_name
529529

530530
@property
531-
def name(self) -> str:
531+
def name(self) -> Optional[str]:
532532
"""Used in registering output data.
533533
534534
:return: The output name
@@ -556,7 +556,7 @@ def name(self, name: str) -> None:
556556
)
557557

558558
@property
559-
def version(self) -> str:
559+
def version(self) -> Optional[str]:
560560
"""Used in registering output data.
561561
562562
:return: The output data

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_validate_funcs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
def validate_common(
2020
cls: Any,
2121
path: Union[str, PathLike, IO[AnyStr]],
22-
validate_func: Callable,
22+
validate_func: Optional[Callable],
2323
params_override: Optional[List[Dict]] = None,
2424
) -> ValidationResult:
2525
params_override = params_override or []

0 commit comments

Comments
 (0)