Skip to content

Commit c163008

Browse files
Type Fix for identity folder (#33479)
* fix aml_on_behalf_of * fix misc * fix misc - 2 * fix managed_identity_client * fix misc - 3 * update pyproject.toml - 1 * update pyproject.toml - 2
1 parent 7166441 commit c163008

15 files changed

+87
-90
lines changed

sdk/ml/azure-ai-ml/azure/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
* Autorest objects.
1010
* SDK v2 support the new YAML file format.
1111
"""
12-
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
12+
__path__ = __import__("pkgutil").extend_path(__path__, __name__)

sdk/ml/azure-ai-ml/azure/ai/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# Copyright (c) Microsoft Corporation. All rights reserved.
33
# ---------------------------------------------------------
44

5-
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
5+
__path__ = __import__("pkgutil").extend_path(__path__, __name__)

sdk/ml/azure-ai-ml/azure/ai/ml/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Copyright (c) Microsoft Corporation. All rights reserved.
33
# ---------------------------------------------------------
44

5-
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
5+
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
66

77
import logging
88

sdk/ml/azure-ai-ml/azure/ai/ml/identity/_aio/_credentials/aml_on_behalf_of.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
import functools
66
import os
7+
from typing import Any, Optional
78

9+
from azure.core.credentials import AccessToken
810
from azure.core.pipeline.transport import HttpRequest
911

1012
from .._internal import AsyncContextManager
@@ -22,10 +24,10 @@ class AzureMLOnBehalfOfCredential(AsyncContextManager):
2224
"""
2325
# pylint: enable=line-too-long
2426

25-
def __init__(self, **kwargs):
27+
def __init__(self, **kwargs: Any):
2628
self._credential = _AzureMLOnBehalfOfCredential(**kwargs)
2729

28-
async def get_token(self, *scopes, **kwargs):
30+
async def get_token(self, *scopes: str, **kwargs: Any) -> AccessToken:
2931
"""Request an access token for `scopes`.
3032
3133
This method is called automatically by Azure SDK clients.
@@ -38,12 +40,12 @@ async def get_token(self, *scopes, **kwargs):
3840

3941
return await self._credential.get_token(*scopes, **kwargs)
4042

41-
async def __aenter__(self):
43+
async def __aenter__(self) -> "AzureMLOnBehalfOfCredential":
4244
if self._credential:
4345
await self._credential.__aenter__()
4446
return self
4547

46-
async def close(self):
48+
async def close(self) -> None:
4749
"""Close the credential's transport session."""
4850
if self._credential:
4951
await self._credential.__aexit__()
@@ -77,7 +79,7 @@ def _get_client_args(**kwargs):
7779

7880

7981
def _get_request(url, resource):
80-
# type: (str, str, dict) -> HttpRequest
82+
# type: (str, str) -> HttpRequest
8183
request = HttpRequest("GET", url)
8284
request.format_parameters(dict({"resource": resource}))
8385
return request

sdk/ml/azure-ai-ml/azure/ai/ml/identity/_aio/_internal/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
# Copyright (c) Microsoft Corporation. All rights reserved.
33
# ---------------------------------------------------------
44
import abc
5+
from typing import Any
56

67

78
class AsyncContextManager(abc.ABC):
89
@abc.abstractmethod
9-
async def close(self):
10+
async def close(self) -> None:
1011
pass
1112

12-
async def __aenter__(self):
13+
async def __aenter__(self) -> "AsyncContextManager":
1314
return self
1415

15-
async def __aexit__(self, *args):
16+
async def __aexit__(self, *args: Any) -> None:
1617
await self.close()
1718

1819

sdk/ml/azure-ai-ml/azure/ai/ml/identity/_aio/_internal/get_token_mixin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __init__(self, *args: "Any", **kwargs: "Any") -> None:
2525
self._last_request_time = 0
2626

2727
# https://github.com/python/mypy/issues/5887
28-
super(GetTokenMixin, self).__init__(*args, **kwargs) # type: ignore
28+
super(GetTokenMixin, self).__init__(*args, **kwargs)
2929

3030
@abc.abstractmethod
3131
# pylint: disable-next=docstring-missing-param

sdk/ml/azure-ai-ml/azure/ai/ml/identity/_aio/_internal/managed_identity_base.py

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

55
import abc
6-
from typing import TYPE_CHECKING, cast
6+
from typing import TYPE_CHECKING, Any, Optional, cast
77

88
from ..._exceptions import CredentialUnavailableError
99
from . import AsyncContextManager
1010
from .get_token_mixin import GetTokenMixin
1111
from .managed_identity_client import AsyncManagedIdentityClient
1212

1313
if TYPE_CHECKING:
14-
from typing import Any, Optional
15-
1614
from azure.core.credentials import AccessToken
1715

1816

1917
class AsyncManagedIdentityBase(AsyncContextManager, GetTokenMixin):
2018
"""Base class for internal credentials using AsyncManagedIdentityClient."""
2119

22-
def __init__(self, **kwargs: "Any") -> None:
20+
def __init__(self, **kwargs: Any) -> None:
2321
super().__init__()
2422
self._client = self.get_client(**kwargs)
2523

2624
@abc.abstractmethod
27-
def get_client(self, **kwargs: "Any") -> "Optional[AsyncManagedIdentityClient]":
25+
def get_client(self, **kwargs: Any) -> "Optional[AsyncManagedIdentityClient]":
2826
pass
2927

3028
@abc.abstractmethod
3129
def get_unavailable_message(self) -> str:
3230
pass
3331

34-
async def __aenter__(self):
32+
async def __aenter__(self) -> "AsyncManagedIdentityBase":
3533
if self._client:
3634
await self._client.__aenter__()
3735
return self
3836

39-
async def __aexit__(self, *args):
37+
async def __aexit__(self, *args: Any) -> None:
4038
if self._client:
4139
await self._client.__aexit__(*args)
4240

sdk/ml/azure-ai-ml/azure/ai/ml/identity/_aio/_internal/managed_identity_client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
# pylint:disable=async-client-bad-name,missing-client-constructor-parameter-credential
2222
class AsyncManagedIdentityClient(AsyncContextManager, ManagedIdentityClientBase):
23-
async def __aenter__(self):
23+
async def __aenter__(self) -> "AsyncManagedIdentityClient":
2424
await self._pipeline.__aenter__()
2525
return self
2626

@@ -30,7 +30,8 @@ async def close(self) -> None:
3030
async def request_token(self, *scopes: str, **kwargs: "Any") -> "AccessToken":
3131
# pylint:disable=invalid-overridden-method
3232
resource = _scopes_to_resource(*scopes)
33-
request = self._request_factory(resource, self._identity_config) # pylint: disable=no-member
33+
# pylint: disable=no-member
34+
request = self._request_factory(resource, self._identity_config) # type: ignore
3435
request_time = int(time.time())
3536
response = await self._pipeline.run(request, retry_on_methods=[request.method], **kwargs)
3637
token = self._process_response(response=response, request_time=request_time, resource=resource)

sdk/ml/azure-ai-ml/azure/ai/ml/identity/_credentials/_AzureMLSparkOnBehalfOfCredential.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import functools
77
import os
8-
from typing import Optional
8+
from typing import Any, Optional
99

1010
from azure.core.pipeline.transport import HttpRequest
1111

@@ -14,7 +14,7 @@
1414

1515

1616
class _AzureMLSparkOnBehalfOfCredential(ManagedIdentityBase):
17-
def get_client(self, **kwargs) -> Optional[ManagedIdentityClient]:
17+
def get_client(self, **kwargs: Any) -> Optional[ManagedIdentityClient]:
1818
client_args = _get_client_args(**kwargs)
1919
if client_args:
2020
return ManagedIdentityClient(**client_args)
@@ -24,7 +24,7 @@ def get_unavailable_message(self) -> str:
2424
return "AzureML Spark On Behalf of credentials not available in this environment"
2525

2626

27-
def _get_client_args(**kwargs) -> Optional[dict]:
27+
def _get_client_args(**kwargs: Any) -> Optional[dict]:
2828
# Override default settings if provided via arguments
2929
if len(kwargs) > 0:
3030
env_key_from_kwargs = [
@@ -80,7 +80,7 @@ def _get_client_args(**kwargs) -> Optional[dict]:
8080
)
8181

8282

83-
def _get_request(url, resource) -> HttpRequest:
83+
def _get_request(url: str, resource: Any) -> HttpRequest:
8484
obo_access_token = os.environ.get("AZUREML_OBO_CANARY_TOKEN")
8585
experiment_name = os.environ.get("AZUREML_ARM_PROJECT_NAME")
8686
run_id = os.environ.get("AZUREML_RUN_ID")

sdk/ml/azure-ai-ml/azure/ai/ml/identity/_credentials/aml_on_behalf_of.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44

55
import functools
66
import os
7+
from typing import Any, Optional, Union
78

9+
from azure.core.credentials import AccessToken
810
from azure.core.pipeline.transport import HttpRequest
911

10-
from ._AzureMLSparkOnBehalfOfCredential import _AzureMLSparkOnBehalfOfCredential
1112
from .._internal.managed_identity_base import ManagedIdentityBase
1213
from .._internal.managed_identity_client import ManagedIdentityClient
14+
from ._AzureMLSparkOnBehalfOfCredential import _AzureMLSparkOnBehalfOfCredential
1315

1416

1517
class AzureMLOnBehalfOfCredential(object):
@@ -23,14 +25,16 @@ class AzureMLOnBehalfOfCredential(object):
2325
"""
2426
# pylint: enable=line-too-long
2527

26-
def __init__(self, **kwargs):
28+
def __init__(self, **kwargs: Any):
2729
provider_type = os.environ.get("AZUREML_DATAPREP_TOKEN_PROVIDER")
30+
self._credential: Union[_AzureMLSparkOnBehalfOfCredential, _AzureMLOnBehalfOfCredential]
31+
2832
if provider_type == "sparkobo": # cspell:disable-line
2933
self._credential = _AzureMLSparkOnBehalfOfCredential(**kwargs)
3034
else:
3135
self._credential = _AzureMLOnBehalfOfCredential(**kwargs)
3236

33-
def get_token(self, *scopes, **kwargs):
37+
def get_token(self, *scopes: str, **kwargs: Any) -> AccessToken:
3438
"""Request an access token for `scopes`.
3539
3640
This method is called automatically by Azure SDK clients.
@@ -43,11 +47,11 @@ def get_token(self, *scopes, **kwargs):
4347

4448
return self._credential.get_token(*scopes, **kwargs)
4549

46-
def __enter__(self):
50+
def __enter__(self) -> "AzureMLOnBehalfOfCredential":
4751
self._credential.__enter__()
4852
return self
4953

50-
def __exit__(self, *args):
54+
def __exit__(self, *args: Any) -> None:
5155
self._credential.__exit__(*args)
5256

5357
def close(self):
@@ -84,7 +88,7 @@ def _get_client_args(**kwargs):
8488

8589

8690
def _get_request(url, resource):
87-
# type: (str, str, dict) -> HttpRequest
91+
# type: (str, str) -> HttpRequest
8892
request = HttpRequest("GET", url)
8993
request.format_parameters(dict({"resource": resource}))
9094
return request

0 commit comments

Comments
 (0)