{Perf} Delay importing MSIAuthenticationWrapper and check_version_compatibility#14331
Merged
{Perf} Delay importing MSIAuthenticationWrapper and check_version_compatibility#14331
Conversation
Collaborator
|
add to S173 |
| try: | ||
| # Import in the `for` loop because `allowed_extensions` can be []. In such case we | ||
| # don't need to import `check_version_compatibility` at all. | ||
| from azure.cli.core.extension.operations import check_version_compatibility |
Contributor
There was a problem hiding this comment.
Importing a module in a for loop is not a good practice.
How much can it benefit from importing in this for loop?
Member
There was a problem hiding this comment.
You can import module as many times as you want in one Python program, no matter what module it is. Every subsequent import after the first accesses the cached module instead of re-evaluating it. So there is no performance penalty.
In reply to: 454774982 [](ancestors = 454774982)
Member
Author
There was a problem hiding this comment.
This is a tricky part. I just want to eliminate an extra if allowed_extensions:. Python has an import cache which will handle "import in a for loop" nicely.
fengzhou-msft
approved these changes
Jul 15, 2020
jiasli
commented
Jul 15, 2020
| is_windows, is_wsl | ||
| from azure.cli.core.cloud import get_active_cloud, set_cloud_subscription | ||
|
|
||
| from .adal_authentication import MSIAuthenticationWrapper |
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fix regressions introduced by
check_version_compatibilityandrequestsexpiresInkey error in cloud shell login credentials for track 2 SDK related commands #14187, which unconditionally importsMSIAuthenticationWrapperandazure.core.credentialsThis PR delays the imports and brings
az versionto its normal speed.Testing Guide