-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
{Pylint} Fix use-dict-literal #30308
base: dev
Are you sure you want to change the base?
Conversation
️✔️AzureCLI-FullTest
|
Hi @atombrella, |
️✔️AzureCLI-BreakingChangeTest
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
Thanks for your contribution. The disabled rules were introduced in #20192. I think it's okay to fix them. Could you please also remove them from |
dict()
with {}
, set([])
with set()
I can do that, but it'll be quite a bit of work. You unfortunately still accept PRs with |
#20192 was created by me. I ignored them simply because we didn't have bandwidth to work on those issues. So yes, please also remove them from Line 45 in be4af71
|
I will fix |
@atombrella, could you remove Line 45 in be4af71
|
dict()
with {}
, set([])
with set()
I've fixed them. There weren't that many after all :) There are quite of cases like: if self.__loadbalancer_models is None:
load_balancer_models = {}
load_balancer_models["ManagedClusterLoadBalancerProfile"] = self.ManagedClusterLoadBalancerProfile
load_balancer_models[
"ManagedClusterLoadBalancerProfileManagedOutboundIPs"
] = self.ManagedClusterLoadBalancerProfileManagedOutboundIPs
load_balancer_models[
"ManagedClusterLoadBalancerProfileOutboundIPs"
] = self.ManagedClusterLoadBalancerProfileOutboundIPs
load_balancer_models[
"ManagedClusterLoadBalancerProfileOutboundIPPrefixes"
] = self.ManagedClusterLoadBalancerProfileOutboundIPPrefixes
load_balancer_models["ResourceReference"] = self.ResourceReference
self.__loadbalancer_models = SimpleNamespace(**load_balancer_models)
return self.__loadbalancer_models If you use PyCharm, it provides a quick and easy way to directly create the dictionary in a single-step. https://pypi.org/project/flake8-comprehensions/ has lots of valuable suggestions. I've fixed the |
53c7e42
to
13492c3
Compare
Some |
This is more Pythonic. Signed-off-by: Mads Jensen <[email protected]>
13492c3
to
9350692
Compare
I did check with ruff to find all of them :) I hadn't heard of ruff before, it seems to quite useful/powerful. C408 is indeed a superset of https://pylint.readthedocs.io/en/stable/user_guide/messages/refactor/use-dict-literal.html There are many great suggestions from flake8-comprehensions. For instance, I experimented briefly today with one of the examples from https://www.geeksforgeeks.org/python-dictionary-fromkeys-method/ to check the performance improvements of using Note that in some places, I reformatted the code slightly. IMO it improves readability to split comprehensions over more lines. One case is: info_dict = {
lun: {"managedDisk": {'storageAccountType': None}}
for lun in dummy_expected if lun != "os"
} |
fc63718
to
0aeed99
Compare
@bebound Could you help with the failed "Azure.azure-cli (Codegen Coverage)". I don't think my changes are related. |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
I created a PR, but I couldn't reproduce the issue. I'll try running |
@@ -107,11 +107,14 @@ def test_subscription_recording_processor_for_response(self): | |||
|
|||
for template in body_templates: | |||
mock_sub_id = str(uuid.uuid4()) | |||
mock_response = dict({'body': {}}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This dict()
is a no-op, not sure why it was written like that in the first place.
Related command
Various commands are "affected" by this. Please check the diff.
Description
flake8-comprehensions has the two suggestions I try to remedy.
You can check the marginal benefits with
timeit
inipython
.I wonder why these two rules are disabled in
pylintrc
. Maybe it's for historic reasons.The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.
I adhere to the Error Handling Guidelines.