Skip to content

Client creation with DefaultAzureCredential raises PyCharm typing warning #25175

Closed

Description

@laiapat

Per #25144, opened by Søren Skov Eriksen (@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.

Activity

  1. added
    Client
    customer-reported
    on Jul 12, 2022
  2. soer7022 commented on Jul 12, 2022

    @soer7022

    The screenshot is from my system, I'm running the following:

    • PyCharm 2022.1.3 (Professional Edition)
    • Python 3.10.1
    • azure-identity 1.10.0
    • azure-keyvault-secrets 4.4.0
  3. laiapat commented on Jul 12, 2022

    @laiapat
    MemberAuthor

    Hi Søren Skov Eriksen (@soer7022)! When you get a chance, would you be willing to try applying the changes from #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.

  4. soer7022 commented on Jul 13, 2022

    @soer7022

    Unfortunately, the changes in the PR did not fix it. And neither did the ones described in the description...
    Did you try updating your PyCharm to a 2022 version? 😄

  5. laiapat commented on Jul 14, 2022

    @laiapat
    MemberAuthor

    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!

  6. laiapat commented on Jul 27, 2022

    @laiapat
    MemberAuthor

    Hi again Søren Skov Eriksen (@soer7022) -- sorry about the delayed response on this, but I was able to reproduce the warning after updating to Community Edition 2022.1.3 🙂 I'll provide an update again as soon as possible.

  7. laiapat commented on Aug 20, 2022

    @laiapat
    MemberAuthor

    A PR is now up to fix this: #25788

  8. 5 remaining items

  9. jlipmanDig commented on Jul 9, 2023

    @jlipmanDig

    Hi, any update on this issue? we're facing something similar which forces us to silence the type-checking for azure credentials

  10. laiapat commented on Jul 10, 2023

    @laiapat
    MemberAuthor

    Hi Jonathan Lipman (@jlipmanDig), I'm working on this issue now and we'll hopefully have a fix included in the next azure-identity release after this week's. A PR should be up later this week -- apologies for the delay.

  11. jlipmanDig commented on Jul 11, 2023

    @jlipmanDig

    Thanks @mccoyp! Looking forward to it 😊

  12. locked and limited conversation to collaborators on Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Azure.CoreAzure.IdentityClientKeyVaultcustomer-reported

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions