question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Client creation with `DefaultAzureCredential` raises PyCharm typing warning

See original GitHub issue

Per 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.

image

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:open
  • Created a year ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
mccoypcommented, Jul 14, 2022

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!

1reaction
mccoypcommented, Jul 13, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Type hinting in PyCharm - JetBrains
PyCharm supports type hinting in function annotations and type comments using the ... If there is a usage error, the corresponding warning is...
Read more >
Python KustoManagementClient using my own credentials
I'm trying to use azure-mgmt-kusto Pkg for some Kusto Cluster operations, using KustoManagementClient. This client requires TokenCredential on ...
Read more >
Backlog Milestone - GitHub
Client creation with DefaultAzureCredential raises PyCharm typing warning Azure.Core Azure.Identity Client This issue points to a problem in the data-plane ...
Read more >
azure-identity - PyPI
When enabled, DefaultAzureCredential falls back to interactively authenticating via the system's default web browser when no other credential is available.
Read more >
Introducing new Azure Monitor libraries for querying Logs and ...
code omitted for brevity var client = new LogsQueryClient(endpoint, new DefaultAzureCredential()); // Query TOP 10 resource groups by event ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found