Skip to content
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

{Misc.} Improve code style and prepare for pylint 3 #29373

Merged
merged 5 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ disable=
superfluous-parens,
implicit-str-concat,
unnecessary-dunder-call,
# These rules were added in Pylint >= 3.2
possibly-used-before-assignment,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rule is hard to fix and make the code hard to read.


[FORMAT]
max-line-length=120
Expand Down
12 changes: 4 additions & 8 deletions src/azure-cli-core/azure/cli/core/aaz/_field_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ def __len__(self):
return len(self._data)

def __iter__(self):
for key in self._data:
yield key
yield from self._data
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/azure-cli-core/azure/cli/core/aaz/_field_value.py:185:8: R1737: Use 'yield from' directly instead of yielding each element one by one (use-yield-from)


def __eq__(self, other):
if isinstance(other, AAZBaseValue):
Expand Down Expand Up @@ -326,8 +325,7 @@ def __init__(self, schema, data):
self._len = 0
if self._data is not None and self._data != AAZUndefined:
for idx in self._data:
if idx + 1 > self._len:
self._len = idx + 1
self._len = max(self._len, idx + 1)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/azure-cli-core/azure/cli/core/aaz/_field_value.py:329:16: R1731: Consider using '_len = max(_len, idx + 1)' instead of unnecessary if block (consider-using-max-builtin)


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

if idx + 1 > self._len:
self._len = idx + 1
self._len = max(self._len, idx + 1)

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

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

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

if idx + 1 > self._len:
self._len = idx + 1
self._len = max(self._len, idx + 1)

def __delitem__(self, idx):
if not isinstance(idx, int):
Expand Down
3 changes: 1 addition & 2 deletions src/azure-cli-core/azure/cli/core/aaz/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ def _print_object_props_schema(cls, schema, title):

prop_group_name = prop_schema._arg_group or ""
header_len = len(prop_name) + len(prop_tags) + (1 if prop_tags else 0)
if header_len > max_header_len:
max_header_len = header_len
max_header_len = max(max_header_len, header_len)
layouts.append({
"name": prop_name,
"tags": prop_tags,
Expand Down
3 changes: 1 addition & 2 deletions src/azure-cli-core/azure/cli/core/aaz/_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,7 @@ def _iter_aaz_object_keys(instance):
if disc_schema is not None:
schemas.append(disc_schema)
for schema in schemas:
for key in schema._fields:
yield key
yield from schema._fields

def _throw_and_show_options(self, instance, part, path, flatten):
parent = '.'.join(path[:-1]).replace('.[', '[')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,7 @@ def find_key_in_json(json_data, key):
if key in k:
yield v
elif isinstance(v, dict):
for id_val in find_key_in_json(v, key):
yield id_val
yield from find_key_in_json(v, key)


def set_location(cmd, sku, location):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ def calculate_weekly_rpo(schedule_run_days):
if backup_scheduled:
if last_active_index is not None:
gap = index - last_active_index
if gap > largest_gap:
largest_gap = gap
largest_gap = max(largest_gap, gap)
last_active_index = index

return largest_gap * 24
Expand Down
3 changes: 1 addition & 2 deletions src/azure-cli/azure/cli/command_modules/network/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1860,8 +1860,7 @@ def pre_operations(self):
def pre_instance_update(self, instance):
def _flatten(collection, expand_property_fn):
for each in collection:
for value in expand_property_fn(each):
yield value
yield from expand_property_fn(each)

if disabled_rule_groups or disabled_rules:
disabled_groups = []
Expand Down