Client creation with `DefaultAzureCredential` raises PyCharm typing warning
See original GitHub issuePer https://github.com/Azure/azure-sdk-for-python/pull/25144, opened by @soer7022. As shown in the screenshot below, PyCharm sometimes raises a flag for incorrect typing when creating a Key Vault SecretClient
with a DefaultAzureCredential
.
DefaultAzureCredential
is an implementation of the TokenCredential
protocol, so the typing is correct (and the type hint on the KV client should be kept as-is for generality). However, we should find a way to indicate this protocol implementation in a way that prevents false flags like this.
Running isinstance(DefaultAzureCredential, TokenCredential)
currently raises an error because TokenCredential
isn’t decorated with @runtime_checkable
, but adding this decorator and running the statement returns True
(mypy
doesn’t raise an error with or without the decorator). This may be the fix we need, but there may be more to do here – refer to PEP 544 for more information.
Issue Analytics
- State:
- Created a year ago
- Comments:8 (6 by maintainers)
Top GitHub Comments
Hmmm… I wasn’t able to keep looking into this today, but I’ll keep trying to repro and provide an update as soon as possible. I updated my PyCharm yesterday, but I’ll see if there are updates I’m missing – thank you for your patience!
Hi @soer7022! When you get a chance, would you be willing to try applying the changes from https://github.com/Azure/azure-sdk-for-python/pull/25187 to your local
azure-core
package to see if that resolves the issue? I haven’t been able to reproduce the warning, possibly because I’m not using PyCharm’s professional edition.If that doesn’t work, I’d be curious to see if the explicit implementation declaration that I described in the linked PR’s description would do the trick.