Skip to content

async DefaultAzureCredential incompatible with AsyncTokenCredential per pyright #27704

Description

Pyright reports a type error when the async DefaultAzureCredential is used anywhere where an AsyncTokenCredential is expected:

  C:\Users\krpratic\azure-sdk-for-python\sdk\cognitivelanguage\azure-ai-language-conversations\samples\async\sample_authentication_async.py:57:66 - error: Argument of type "DefaultAzureCredential" cannot be assigned to parameter "credential" of type "AzureKeyCredential | AsyncTokenCredential" in function "__init__"
    Type "DefaultAzureCredential" cannot be assigned to type "AzureKeyCredential | AsyncTokenCredential"
      "DefaultAzureCredential" is incompatible with "AzureKeyCredential"
      "DefaultAzureCredential" is incompatible with protocol "AsyncTokenCredential"
        "__aenter__" is an incompatible type
          Type "() -> Coroutine[Any, Any, DefaultAzureCredential]" cannot be assigned to type "() -> Coroutine[Any, Any, None]"
            Function return type "Coroutine[Any, Any, DefaultAzureCredential]" is incompatible with type "Coroutine[Any, Any, None]"
        "__aexit__" is an incompatible type
          Type "(*args: Unknown) -> Coroutine[Any, Any, None]" cannot be assigned to type "(exc_type: Unknown, exc_value: Unknown, traceback: Unknown) -> Coroutine[Any, Any, None]"

This is due to the difference in how the Protocol is typed vs. how it is typed in identity:

async def close(self) -> None:
pass
async def __aenter__(self):
pass
async def __aexit__(self, exc_type, exc_value, traceback) -> None:
pass

class AsyncContextManager(abc.ABC):
@abc.abstractmethod
async def close(self):
pass
async def __aenter__(self):
return self
async def __aexit__(self, *args):
await self.close()

Note that this doesn't occur with the sync credential since __enter__ and __exit__ are not described by TokenCredential.

Metadata

Metadata

Labels

Azure.CoreAzure.IdentityClientThis issue points to a problem in the data-plane of the library.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions