-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Conversation
️✔️AzureCLI-FullTest
|
️✔️AzureCLI-BreakingChangeTest
|
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) |
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.
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:
- These
xxx-hint
configs never take effect, asinvalid-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.
- The default value is enough, for example,
module-naming-style
issnake_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.
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 is very nice investigation and makes the context much clearer.
@@ -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)) |
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 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'])) |
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.
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?") |
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.
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] |
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.
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] |
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.
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' |
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.
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()))) |
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.
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: |
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.
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)
bbe1967
to
da25845
Compare
@@ -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 |
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 line needs to be removed when azdev is released.
Really detailed explanation for every change! Nice work! @bebound |
@bebound, you have done an outstanding job with great attention to detail. |
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
Disabled rules:
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 featureThis checklist is used to make sure that common guidelines for a pull request are followed.
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.