Skip to content

Commit a9c6b39

Browse files
authored
{Pylint} Fix use-dict-literal (#30308)
1 parent d2cd62b commit a9c6b39

File tree

45 files changed

+167
-148
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+167
-148
lines changed

pylintrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ disable=
4242
use-maxsplit-arg,
4343
arguments-renamed,
4444
consider-using-in,
45-
use-dict-literal,
4645
consider-using-dict-items,
4746
consider-using-enumerate,
4847
# These rules were added in Pylint >= 2.12, disable them to avoid making retroactive change

scripts/temp_help/help_convert.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,23 +173,23 @@ def get_all_mod_names():
173173

174174
def _get_new_yaml_dict(help_dict):
175175

176-
result = dict(version=1, content=[])
176+
result = {"version": 1, "content": []}
177177
content = result['content']
178178

179179
for command_or_group, yaml_text in help_dict.items():
180180
help_dict = yaml.safe_load(yaml_text)
181181

182182
type = help_dict["type"]
183183

184-
elem = {type: dict(name=command_or_group)}
184+
elem = {type: {"name": command_or_group}}
185185
elem_content = elem[type]
186186

187187
_convert_summaries(old_dict=help_dict, new_dict=elem_content)
188188

189189
if "parameters" in help_dict:
190190
parameters = []
191191
for param in help_dict["parameters"]:
192-
new_param = dict()
192+
new_param = {}
193193
if "name" in param:
194194
options = param["name"].split()
195195
new_param["name"] = max(options, key=lambda x: len(x))
@@ -205,7 +205,7 @@ def _get_new_yaml_dict(help_dict):
205205
if "examples" in help_dict:
206206
elem_examples = []
207207
for ex in help_dict["examples"]:
208-
new_ex = dict()
208+
new_ex = {}
209209
if "name" in ex:
210210
new_ex["summary"] = ex["name"]
211211
if "text" in ex:

src/azure-cli-core/azure/cli/core/aaz/_field_value.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ def to_serialized_data(self, processor=None, keep_undefined_in_list=False, # py
449449

450450
class AAZIdentityObject(AAZObject): # pylint: disable=too-few-public-methods
451451
def to_serialized_data(self, processor=None, **kwargs):
452-
calculate_data = dict()
452+
calculate_data = {}
453453
if self._data == AAZUndefined:
454454
result = AAZUndefined
455455

src/azure-cli-core/azure/cli/core/command_recommender.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ def get_parameter_kwargs(args):
462462
:type: dict
463463
"""
464464

465-
parameter_kwargs = dict()
465+
parameter_kwargs = {}
466466
for index, parameter in enumerate(args):
467467
if parameter.startswith('-'):
468468

@@ -501,7 +501,7 @@ def get_user_param_value(target_param):
501501
:return: The replaced value for target_param
502502
:type: str
503503
"""
504-
standard_source_kwargs = dict()
504+
standard_source_kwargs = {}
505505

506506
for param, val in source_kwargs.items():
507507
if param in param_mappings:

src/azure-cli-core/azure/cli/core/commands/command_operation.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ def get_op_handler(self, op_path):
6868
def load_getter_op_arguments(self, getter_op_path, cmd_args=None):
6969
""" Load arguments from function signature of getter command op """
7070
op = self.get_op_handler(getter_op_path)
71-
getter_args = dict(
72-
extract_args_from_signature(op, excluded_params=EXCLUDED_PARAMS))
71+
getter_args = dict(extract_args_from_signature(op, excluded_params=EXCLUDED_PARAMS))
7372
cmd_args = cmd_args or {}
7473
cmd_args.update(getter_args)
7574
# The cmd argument is required when calling self.handler function.

src/azure-cli-core/azure/cli/core/commands/parameters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ def expand(self, dest, model_type, group_name=None, patches=None):
420420
return
421421

422422
if not patches:
423-
patches = dict()
423+
patches = {}
424424

425425
# fetch the documentation for model parameters first. for models, which are the classes
426426
# derive from msrest.serialization.Model and used in the SDK API to carry parameters, the
@@ -440,7 +440,7 @@ def _expansion_validator_impl(namespace):
440440
:return: The argument of specific type.
441441
"""
442442
ns = vars(namespace)
443-
kwargs = dict((k, ns[k]) for k in ns if k in set(expanded_arguments))
443+
kwargs = {k: ns[k] for k in ns if k in set(expanded_arguments)}
444444

445445
setattr(namespace, assigned_arg, model_type(**kwargs))
446446

src/azure-cli-core/azure/cli/core/commands/template_create.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,22 @@ def _validate_name_or_id(
5959
resource_id_parts = parse_resource_id(property_value)
6060
value_supplied_was_id = True
6161
elif has_parent:
62-
resource_id_parts = dict(
63-
name=parent_value,
64-
resource_group=resource_group_name,
65-
namespace=parent_type.split('/')[0],
66-
type=parent_type.split('/')[1],
67-
subscription=get_subscription_id(cli_ctx),
68-
child_name_1=property_value,
69-
child_type_1=property_type)
62+
resource_id_parts = {
63+
"name": parent_value,
64+
"resource_group": resource_group_name,
65+
"namespace": parent_type.split('/')[0],
66+
"type": parent_type.split('/')[1],
67+
"subscription": get_subscription_id(cli_ctx),
68+
"child_name_1": property_value,
69+
"child_type_1": property_type}
7070
value_supplied_was_id = False
7171
else:
72-
resource_id_parts = dict(
73-
name=property_value,
74-
resource_group=resource_group_name,
75-
namespace=property_type.split('/')[0],
76-
type=property_type.split('/')[1],
77-
subscription=get_subscription_id(cli_ctx))
72+
resource_id_parts = {
73+
"name": property_value,
74+
"resource_group": resource_group_name,
75+
"namespace": property_type.split('/')[0],
76+
"type": property_type.split('/')[1],
77+
"subscription": get_subscription_id(cli_ctx)}
7878
value_supplied_was_id = False
7979
return (resource_id_parts, value_supplied_was_id)
8080

src/azure-cli-core/azure/cli/core/tests/test_util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ def test_handle_exception_httpoperationerror_typical_response_error(self, mock_l
514514
# create test HttpOperationError Exception
515515
err_msg = "Bad Request because of some incorrect param"
516516
err_code = "BadRequest"
517-
err = dict(error=dict(code=err_code, message=err_msg))
517+
err = {"error": {"code": err_code, "message": err_msg}}
518518
response_text = json.dumps(err)
519519
mock_http_error = self._get_mock_HttpOperationError(response_text)
520520

@@ -533,7 +533,7 @@ def test_handle_exception_httpoperationerror_error_key_has_string_value(self, mo
533533

534534
# create test HttpOperationError Exception
535535
err_msg = "BadRequest"
536-
err = dict(error=err_msg)
536+
err = {"error": err_msg}
537537
response_text = json.dumps(err)
538538
mock_http_error = self._get_mock_HttpOperationError(response_text)
539539

src/azure-cli-telemetry/azure/cli/telemetry/components/telemetry_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class CliTelemetryClient:
2323
def __init__(self, batch=100, sender=None):
2424
from azure.cli.telemetry.components.telemetry_logging import get_logger
2525

26-
self._clients = dict()
26+
self._clients = {}
2727
self._counter = 0
2828
self._batch = batch
2929
self._sender = sender or _NoRetrySender

src/azure-cli-testsdk/azure/cli/testsdk/scenario_tests/tests/test_recording_processor.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,14 @@ def test_subscription_recording_processor_for_response(self):
107107

108108
for template in body_templates:
109109
mock_sub_id = str(uuid.uuid4())
110-
mock_response = dict({'body': {}})
111-
mock_response['body']['string'] = template.format(mock_sub_id)
112-
mock_response['headers'] = {'Location': [location_header_template.format(mock_sub_id)],
113-
'azure-asyncoperation': [asyncoperation_header_template.format(mock_sub_id)],
114-
'content-type': ['application/json']}
110+
mock_response = {
111+
'body': {'string': template.format(mock_sub_id)},
112+
'headers': {
113+
'Location': [location_header_template.format(mock_sub_id)],
114+
'azure-asyncoperation': [asyncoperation_header_template.format(mock_sub_id)],
115+
'content-type': ['application/json'],
116+
}
117+
}
115118
rp.process_response(mock_response)
116119
self.assertEqual(mock_response['body']['string'], template.format(replaced_subscription_id))
117120

@@ -127,11 +130,12 @@ def test_recording_processor_skip_body_on_unrecognized_content_type(self):
127130
rp = SubscriptionRecordingProcessor(replaced_subscription_id)
128131

129132
mock_sub_id = str(uuid.uuid4())
130-
mock_response = dict({'body': {}})
131-
mock_response['body']['string'] = mock_sub_id
132-
mock_response['headers'] = {
133-
'Location': [location_header_template.format(mock_sub_id)],
134-
'content-type': ['application/foo']
133+
mock_response = {
134+
'body': {'string': mock_sub_id},
135+
'headers': {
136+
'Location': [location_header_template.format(mock_sub_id)],
137+
'content-type': ['application/foo'],
138+
}
135139
}
136140

137141
# action

0 commit comments

Comments
 (0)