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 2.17 #26685

Merged
merged 14 commits into from
Jul 17, 2023

Conversation

bebound
Copy link
Contributor

@bebound bebound commented Jun 15, 2023

Description

Ensure that the CI passes in the new azdev(Azure/azure-cli-dev-tools#359) and prepare for Python 3.11 support.

Azure is compatible with flake8 6.0 in #25370

Testing Guide

History Notes

[Component Name 1] BREAKING CHANGE: az command a: Make some customer-facing breaking change
[Component Name 2] az command b: Add some customer-facing feature


This checklist is used to make sure that common guidelines for a pull request are followed.

@azure-client-tools-bot-prd
Copy link

azure-client-tools-bot-prd bot commented Jun 15, 2023

️✔️AzureCLI-FullTest
️✔️acr
️✔️2020-09-01-hybrid
️✔️3.10
️✔️3.9
️✔️latest
️✔️3.10
️✔️3.9
️✔️acs
️✔️2020-09-01-hybrid
️✔️3.10
️✔️3.9
️✔️latest
️✔️3.10
️✔️3.9
️✔️advisor
️✔️latest
️✔️3.10
️✔️3.9
️✔️ams
️✔️latest
️✔️3.10
️✔️3.9
️✔️apim
️✔️latest
️✔️3.10
️✔️3.9
️✔️appconfig
️✔️latest
️✔️3.10
️✔️3.9
️✔️appservice
️✔️latest
️✔️3.10
️✔️3.9
️✔️aro
️✔️latest
️✔️3.10
️✔️3.9
️✔️backup
️✔️latest
️✔️3.10
️✔️3.9
️✔️batch
️✔️latest
️✔️3.10
️✔️3.9
️✔️batchai
️✔️latest
️✔️3.10
️✔️3.9
️✔️billing
️✔️latest
️✔️3.10
️✔️3.9
️✔️botservice
️✔️latest
️✔️3.10
️✔️3.9
️✔️cdn
️✔️latest
️✔️3.10
️✔️3.9
️✔️cloud
️✔️latest
️✔️3.10
️✔️3.9
️✔️cognitiveservices
️✔️latest
️✔️3.10
️✔️3.9
️✔️config
️✔️latest
️✔️3.10
️✔️3.9
️✔️configure
️✔️latest
️✔️3.10
️✔️3.9
️✔️consumption
️✔️latest
️✔️3.10
️✔️3.9
️✔️container
️✔️latest
️✔️3.10
️✔️3.9
️✔️core
️✔️2018-03-01-hybrid
️✔️3.10
️✔️3.9
️✔️2019-03-01-hybrid
️✔️3.10
️✔️3.9
️✔️2020-09-01-hybrid
️✔️3.10
️✔️3.9
️✔️latest
️✔️3.10
️✔️3.9
️✔️cosmosdb
️✔️latest
️✔️3.10
️✔️3.9
️✔️databoxedge
️✔️2019-03-01-hybrid
️✔️3.10
️✔️3.9
️✔️2020-09-01-hybrid
️✔️3.10
️✔️3.9
️✔️latest
️✔️3.10
️✔️3.9
️✔️dla
️✔️latest
️✔️3.10
️✔️3.9
️✔️dls
️✔️latest
️✔️3.10
️✔️3.9
️✔️dms
️✔️latest
️✔️3.10
️✔️3.9
️✔️eventgrid
️✔️latest
️✔️3.10
️✔️3.9
️✔️eventhubs
️✔️latest
️✔️3.10
️✔️3.9
️✔️feedback
️✔️latest
️✔️3.10
️✔️3.9
️✔️find
️✔️latest
️✔️3.10
️✔️3.9
️✔️hdinsight
️✔️latest
️✔️3.10
️✔️3.9
️✔️identity
️✔️latest
️✔️3.10
️✔️3.9
️✔️iot
️✔️2019-03-01-hybrid
️✔️3.10
️✔️3.9
️✔️2020-09-01-hybrid
️✔️3.10
️✔️3.9
️✔️latest
️✔️3.10
️✔️3.9
️✔️keyvault
️✔️2018-03-01-hybrid
️✔️3.10
️✔️3.9
️✔️2020-09-01-hybrid
️✔️3.10
️✔️3.9
️✔️latest
️✔️3.10
️✔️3.9
️✔️kusto
️✔️latest
️✔️3.10
️✔️3.9
️✔️lab
️✔️latest
️✔️3.10
️✔️3.9
️✔️managedservices
️✔️latest
️✔️3.10
️✔️3.9
️✔️maps
️✔️latest
️✔️3.10
️✔️3.9
️✔️marketplaceordering
️✔️latest
️✔️3.10
️✔️3.9
️✔️monitor
️✔️latest
️✔️3.10
️✔️3.9
️✔️mysql
️✔️latest
️✔️3.10
️✔️3.9
️✔️netappfiles
️✔️latest
️✔️3.10
️✔️3.9
️✔️network
️✔️2018-03-01-hybrid
️✔️3.10
️✔️3.9
️✔️latest
️✔️3.10
️✔️3.9
️✔️policyinsights
️✔️latest
️✔️3.10
️✔️3.9
️✔️privatedns
️✔️latest
️✔️3.10
️✔️3.9
️✔️profile
️✔️latest
️✔️3.10
️✔️3.9
️✔️rdbms
️✔️latest
️✔️3.10
️✔️3.9
️✔️redis
️✔️latest
️✔️3.10
️✔️3.9
️✔️relay
️✔️latest
️✔️3.10
️✔️3.9
️✔️resource
️✔️2018-03-01-hybrid
️✔️3.10
️✔️3.9
️✔️2019-03-01-hybrid
️✔️3.10
️✔️3.9
️✔️latest
️✔️3.10
️✔️3.9
️✔️role
️✔️latest
️✔️3.10
️✔️3.9
️✔️search
️✔️latest
️✔️3.10
️✔️3.9
️✔️security
️✔️latest
️✔️3.10
️✔️3.9
️✔️servicebus
️✔️latest
️✔️3.10
️✔️3.9
️✔️serviceconnector
️✔️latest
️✔️3.10
️✔️3.9
️✔️servicefabric
️✔️latest
️✔️3.10
️✔️3.9
️✔️signalr
️✔️latest
️✔️3.10
️✔️3.9
️✔️sql
️✔️latest
️✔️3.10
️✔️3.9
️✔️sqlvm
️✔️latest
️✔️3.10
️✔️3.9
️✔️storage
️✔️2018-03-01-hybrid
️✔️3.10
️✔️3.9
️✔️2019-03-01-hybrid
️✔️3.10
️✔️3.9
️✔️2020-09-01-hybrid
️✔️3.10
️✔️3.9
️✔️latest
️✔️3.10
️✔️3.9
️✔️synapse
️✔️latest
️✔️3.10
️✔️3.9
️✔️telemetry
️✔️2018-03-01-hybrid
️✔️3.10
️✔️3.9
️✔️2019-03-01-hybrid
️✔️3.10
️✔️3.9
️✔️2020-09-01-hybrid
️✔️3.10
️✔️3.9
️✔️latest
️✔️3.10
️✔️3.9
️✔️util
️✔️latest
️✔️3.10
️✔️3.9
️✔️vm
️✔️2018-03-01-hybrid
️✔️3.10
️✔️3.9
️✔️2019-03-01-hybrid
️✔️3.10
️✔️3.9
️✔️2020-09-01-hybrid
️✔️3.10
️✔️3.9
️✔️latest
️✔️3.10
️✔️3.9

@azure-client-tools-bot-prd
Copy link

azure-client-tools-bot-prd bot commented Jun 15, 2023

️✔️AzureCLI-BreakingChangeTest
️✔️Non Breaking Changes

@yonzhan
Copy link
Collaborator

yonzhan commented Jun 15, 2023

Misc.

function-name-hint=lower_case_with_underscores
argument-name-hint=lower_case_with_underscores
variable-name-hint=lower_case_with_underscores
inlinevar-name-hint=lower_case_with_underscores (short is OK)
Copy link
Contributor Author

@bebound bebound Jun 15, 2023

Choose a reason for hiding this comment

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

xxx-hint is shown when pylint found invalid name:
demo/demo.py:19:0: C0103: Class name "aa" doesn't conform to '{invalid-classname-hint}' pattern ('[_]{0,2}[A-Z]{1}[A-Za-z0-9]{0,30}$' pattern) (invalid-name) (pylint-dev/pylint#2663)

I remove these configs:

  1. These xxx-hint configs never take effect, as invalid-name is disabled since first commit: Touch up pylintrc #3806. This is also mentioned in the comment:

The invalid-name checker must be enabled for these hints to be used.

  1. The default value is enough, for example, module-naming-style is snake_case.

PS:
variable-name-hint raises error from pylint 2.14: pylint-dev/pylint#6931
These options changes to xxxx-style, see https://pylint.pycqa.org/en/latest/user_guide/configuration/all-options.html#basic-checker.

Copy link
Member

Choose a reason for hiding this comment

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

This is very nice investigation and makes the context much clearer.

@bebound bebound changed the title [Misc.] Bump azdev [Misc.] Improve code style and prepare for new azdev Jun 26, 2023
@@ -520,7 +520,7 @@ def delete_staticsite(cmd, name, resource_group_name=None, no_wait=False):

def _parse_pair(pair, delimiter):
if delimiter not in pair:
InvalidArgumentValueError("invalid format of pair {0}".format(pair))
raise InvalidArgumentValueError("invalid format of pair {0}".format(pair))
Copy link
Contributor Author

@bebound bebound Jun 27, 2023

Choose a reason for hiding this comment

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

This line makes no sense without raise.

W0133: Exception statement has no effect (pointless-exception-statement)

if kwargs[self._request_param['name']] is None:
raise ValueError(message.format(self._request_param['model']))
if kwargs[self._request_param['name']] is None:
raise ValueError(message.format(self._request_param['model']))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

R1720: Unnecessary "else" after "raise", remove the "else" and de-indent the code inside it (no-else-raise)

@@ -309,11 +309,11 @@ def ensure_aks_acr_role_assignment(cmd, assignee, registry_id, detach=False, is_
if not delete_role_assignments(
cmd.cli_ctx, "acrpull", assignee, scope=registry_id, is_service_principal=is_service_principal
):
raise AzCLIError("Could not delete role assignments for ACR. " "Are you an Owner on this subscription?")
raise AzCLIError("Could not delete role assignments for ACR. Are you an Owner on this subscription?")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

W1404: Implicit string concatenation found in call (implicit-str-concat)

@@ -122,7 +122,7 @@ def items(self):
return self.__store.items()

def __format_count(self):
untouched_keys = [x for x in self.__store.keys() if x not in self.__count.keys()]
untouched_keys = [x for x in self.__store if x not in self.__count]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

C0201: Consider iterating the dictionary directly instead of calling .keys() (consider-iterating-dictionary)

@@ -285,7 +285,7 @@ def _validate_ip_address_existence(cmd, namespace):
scm_site = namespace.scm_site
configs = _generic_site_operation(cmd.cli_ctx, resource_group_name, name, 'get_configuration', slot)
access_rules = configs.scm_ip_security_restrictions if scm_site else configs.ip_security_restrictions
ip_exists = [(lambda x: x.ip_address == namespace.ip_address)(x) for x in access_rules]
ip_exists = [x.ip_address == namespace.ip_address for x in access_rules]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

C3002: Lambda expression called directly. Execute the expression inline instead. (unnecessary-direct-lambda-call)

@@ -437,7 +437,7 @@ def replace_memory_optimized_tier(result):
for capability_idx, capability in enumerate(result):
for edition_idx, edition in enumerate(capability.supported_flexible_server_editions):
if edition.name == 'MemoryOptimized':
result[capability_idx].supported_flexible_server_editions[edition_idx].name = 'BusinessCritical'
capability.supported_flexible_server_editions[edition_idx].name = 'BusinessCritical'
Copy link
Contributor Author

@bebound bebound Jun 27, 2023

Choose a reason for hiding this comment

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

R1736: Unnecessary list index lookup, use 'capability' instead (unnecessary-list-index-lookup)

@@ -56,7 +56,7 @@ def list_tables(client, num_results=None, marker=None, show_next_marker=None):

def exists(client, table_name):
generator = client.query_tables("TableName eq '{}'".format(table_name))
return list(next(generator.by_page())) != []
return bool(list(next(generator.by_page())))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

C1803: 'list(...) != []' can be simplified to 'list(...)' as an empty list is falsey (use-implicit-booleaness-not-comparison)

@@ -461,7 +461,7 @@ def _get_scale_settings(initial_count, min_count, max_count):
if not initial_count and not min_count and not max_count:
# Get from the config file
return None
if sum([1 if v is not None else 0 for v in (min_count, max_count)]) == 1:
if sum(1 if v is not None else 0 for v in (min_count, max_count)) == 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.

R1728: Consider using a generator instead 'sum(1 if v is not None else 0 for v in (min_count, max_count))' (consider-using-generator)

@bebound bebound changed the title [Misc.] Improve code style and prepare for new azdev [Misc.] Improve code style and prepare for pylint 2.17 Jun 27, 2023
@bebound bebound force-pushed the bump-azdev branch 2 times, most recently from bbe1967 to da25845 Compare June 30, 2023 02:15
@bebound bebound closed this Jul 5, 2023
@bebound bebound reopened this Jul 5, 2023
@@ -16,7 +16,7 @@ steps:
chmod +x env/bin/activate
. env/bin/activate
python -m pip install -U pip
pip install azdev
pip install git+https://github.com/dciborow/azure-cli-dev-tools.git@dciborow/pylint
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 line needs to be removed when azdev is released.

@bebound bebound marked this pull request as ready for review July 10, 2023 08:44
@jiasli
Copy link
Member

jiasli commented Jul 11, 2023

Really detailed explanation for every change! Nice work! @bebound

wangzelin007
wangzelin007 previously approved these changes Jul 12, 2023
@wangzelin007
Copy link
Member

@bebound, you have done an outstanding job with great attention to detail.

@bebound bebound changed the title [Misc.] Improve code style and prepare for pylint 2.17 {Misc.} Improve code style and prepare for pylint 2.17 Jul 13, 2023
@bebound bebound merged commit 15296fd into Azure:dev Jul 17, 2023
96 checks passed
@bebound bebound deleted the bump-azdev branch July 17, 2023 06:49
avgale pushed a commit to avgale/azure-cli that referenced this pull request Aug 24, 2023
@bebound bebound mentioned this pull request Aug 24, 2023
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants