Skip to content

Commit e6e90de

Browse files
authored
add default impl for AsyncTokenCred (#31585)
* add default impl for AsyncTokenCred * update * update * update * update * update * update * update * update changelog * update
1 parent 6470562 commit e6e90de

File tree

7 files changed

+46
-10
lines changed

7 files changed

+46
-10
lines changed

eng/tox/install_depend_packages.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
MINIMUM_VERSION_GENERIC_OVERRIDES = {
3535
"azure-common": "1.1.10",
3636
"msrest": "0.6.10",
37-
"typing-extensions": "3.6.5",
37+
"typing-extensions": "4.6.0",
3838
"opentelemetry-api": "1.3.0",
3939
"opentelemetry-sdk": "1.3.0",
4040
"azure-core": "1.11.0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"reportUnnecessaryCast": "warning",
3+
"reportUnnecessaryTypeIgnoreComment": "warning",
4+
"reportTypeCommentUsage": true,
5+
"pythonVersion": "3.10",
6+
"reportMissingImports": false,
7+
"exclude": [
8+
"**/samples/async/sample_authentication_async.py"
9+
]
10+
}

sdk/containerregistry/azure-containerregistry/azure/containerregistry/aio/_async_anonymous_exchange_client.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
# Copyright (c) Microsoft Corporation.
44
# Licensed under the MIT License.
55
# ------------------------------------
6-
from typing import Optional, Union
6+
from types import TracebackType
7+
from typing import Optional, Union, Type
78

89
from azure.core.credentials import AccessToken
910
from azure.core.credentials_async import AsyncTokenCredential
@@ -27,7 +28,12 @@ async def close(self) -> None:
2728
async def __aenter__(self):
2829
pass
2930

30-
async def __aexit__(self, exc_type, exc_value, traceback) -> None:
31+
async def __aexit__(
32+
self,
33+
exc_type: Optional[Type[BaseException]] = None,
34+
exc_value: Optional[BaseException] = None,
35+
traceback: Optional[TracebackType] = None,
36+
) -> None:
3137
pass
3238

3339

sdk/core/azure-core/CHANGELOG.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# Release History
22

3-
## 1.29.2 (Unreleased)
4-
5-
### Features Added
6-
7-
### Breaking Changes
3+
## 1.29.2 (2023-08-14)
84

95
### Bugs Fixed
106

7+
- Added a default implementation for `AsyncTokenCredential.__aexit__()` #31573
8+
119
### Other Changes
1210

11+
- Bumped `typing-extensions` version to 4.6.0.
12+
1313
## 1.29.1 (2023-08-09)
1414

1515
### Bugs Fixed

sdk/core/azure-core/azure/core/credentials_async.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
# Licensed under the MIT License.
44
# ------------------------------------
55
from __future__ import annotations
6-
from typing import Any, Optional, AsyncContextManager
6+
from types import TracebackType
7+
from typing import Any, Optional, AsyncContextManager, Type
78
from typing_extensions import Protocol, runtime_checkable
89
from .credentials import AccessToken as _AccessToken
910

@@ -31,3 +32,11 @@ async def get_token(
3132

3233
async def close(self) -> None:
3334
pass
35+
36+
async def __aexit__(
37+
self,
38+
exc_type: Optional[Type[BaseException]] = None,
39+
exc_value: Optional[BaseException] = None,
40+
traceback: Optional[TracebackType] = None,
41+
) -> None:
42+
pass

sdk/core/azure-core/setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
install_requires=[
7171
"requests>=2.18.4",
7272
"six>=1.11.0",
73-
"typing-extensions>=4.3.0",
73+
"typing-extensions>=4.6.0",
7474
],
7575
extras_require={
7676
"aio": [

sdk/core/azure-core/tests/async_tests/test_authentication_async.py

+11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from requests import Response
1010

1111
from azure.core.credentials import AccessToken
12+
from azure.core.credentials_async import AsyncTokenCredential
1213
from azure.core.exceptions import ServiceRequestError
1314
from azure.core.pipeline import AsyncPipeline
1415
from azure.core.pipeline.policies import (
@@ -429,3 +430,13 @@ async def get_token(*_, **__):
429430
pipeline = AsyncPipeline(transport=MockTransport(), policies=[redirect_policy, auth_policy, header_clean_up_policy])
430431

431432
await pipeline.run(HttpRequest("GET", "https://localhost"))
433+
434+
435+
@pytest.mark.asyncio
436+
async def test_async_token_credential_inheritance():
437+
class TestTokenCredential(AsyncTokenCredential):
438+
async def get_token(self, *scopes, **kwargs):
439+
return "TOKEN"
440+
441+
cred = TestTokenCredential()
442+
await cred.get_token("scope")

0 commit comments

Comments
 (0)