Skip to content

Commit 09422be

Browse files
authored
{Misc.} Improve code style and prepare for pylint 3 (Azure#29373)
1 parent 413d13a commit 09422be

File tree

7 files changed

+11
-18
lines changed

7 files changed

+11
-18
lines changed

pylintrc

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ disable=
5353
superfluous-parens,
5454
implicit-str-concat,
5555
unnecessary-dunder-call,
56+
# These rules were added in Pylint >= 3.2
57+
possibly-used-before-assignment,
5658

5759
[FORMAT]
5860
max-line-length=120

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

+4-8
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ def __len__(self):
182182
return len(self._data)
183183

184184
def __iter__(self):
185-
for key in self._data:
186-
yield key
185+
yield from self._data
187186

188187
def __eq__(self, other):
189188
if isinstance(other, AAZBaseValue):
@@ -326,8 +325,7 @@ def __init__(self, schema, data):
326325
self._len = 0
327326
if self._data is not None and self._data != AAZUndefined:
328327
for idx in self._data:
329-
if idx + 1 > self._len:
330-
self._len = idx + 1
328+
self._len = max(self._len, idx + 1)
331329

332330
def __getitem__(self, idx) -> AAZBaseValue:
333331
if not isinstance(idx, int):
@@ -341,8 +339,7 @@ def __getitem__(self, idx) -> AAZBaseValue:
341339
if idx not in self._data:
342340
self._data[idx] = AAZValuePatch.build(item_schema)
343341

344-
if idx + 1 > self._len:
345-
self._len = idx + 1
342+
self._len = max(self._len, idx + 1)
346343

347344
return item_schema._ValueCls(item_schema, self._data[idx])
348345

@@ -362,8 +359,7 @@ def __setitem__(self, idx, data):
362359

363360
self._data[idx] = item_schema.process_data(data, key=idx)
364361

365-
if idx + 1 > self._len:
366-
self._len = idx + 1
362+
self._len = max(self._len, idx + 1)
367363

368364
def __delitem__(self, idx):
369365
if not isinstance(idx, int):

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ def _print_object_props_schema(cls, schema, title):
120120

121121
prop_group_name = prop_schema._arg_group or ""
122122
header_len = len(prop_name) + len(prop_tags) + (1 if prop_tags else 0)
123-
if header_len > max_header_len:
124-
max_header_len = header_len
123+
max_header_len = max(max_header_len, header_len)
125124
layouts.append({
126125
"name": prop_name,
127126
"tags": prop_tags,

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -652,8 +652,7 @@ def _iter_aaz_object_keys(instance):
652652
if disc_schema is not None:
653653
schemas.append(disc_schema)
654654
for schema in schemas:
655-
for key in schema._fields:
656-
yield key
655+
yield from schema._fields
657656

658657
def _throw_and_show_options(self, instance, part, path, flatten):
659658
parent = '.'.join(path[:-1]).replace('.[', '[')

src/azure-cli/azure/cli/command_modules/appservice/_create_util.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,7 @@ def find_key_in_json(json_data, key):
305305
if key in k:
306306
yield v
307307
elif isinstance(v, dict):
308-
for id_val in find_key_in_json(v, key):
309-
yield id_val
308+
yield from find_key_in_json(v, key)
310309

311310

312311
def set_location(cmd, sku, location):

src/azure-cli/azure/cli/command_modules/backup/custom_help.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,7 @@ def calculate_weekly_rpo(schedule_run_days):
238238
if backup_scheduled:
239239
if last_active_index is not None:
240240
gap = index - last_active_index
241-
if gap > largest_gap:
242-
largest_gap = gap
241+
largest_gap = max(largest_gap, gap)
243242
last_active_index = index
244243

245244
return largest_gap * 24

src/azure-cli/azure/cli/command_modules/network/custom.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1860,8 +1860,7 @@ def pre_operations(self):
18601860
def pre_instance_update(self, instance):
18611861
def _flatten(collection, expand_property_fn):
18621862
for each in collection:
1863-
for value in expand_property_fn(each):
1864-
yield value
1863+
yield from expand_property_fn(each)
18651864

18661865
if disabled_rule_groups or disabled_rules:
18671866
disabled_groups = []

0 commit comments

Comments
 (0)