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

{Pylint} Fix superfluous-parens #30361

Merged
merged 6 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 0 additions & 1 deletion pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ disable=
used-before-assignment,
# These rules were added in Pylint >= 2.12, disable them to avoid making retroactive change
missing-timeout,
superfluous-parens,
implicit-str-concat,
unnecessary-dunder-call,
# These rules were added in Pylint >= 3.2
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli-core/azure/cli/core/_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ def refresh_accounts(self):
if user_name in refreshed_list:
continue
refreshed_list.add(user_name)
is_service_principal = (s[_USER_ENTITY][_USER_TYPE] == _SERVICE_PRINCIPAL)
is_service_principal = s[_USER_ENTITY][_USER_TYPE] == _SERVICE_PRINCIPAL
tenant = s[_TENANT_ID]
subscriptions = []
try:
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli-core/azure/cli/core/commands/arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def parse_ids_arguments(_, command, args):
# ensure the required parameters are provided if --ids is not
errors = [arg for arg in required_args if getattr(namespace, arg.name, None) is None]
if errors:
missing_required = ' '.join((arg.options_list[0] for arg in errors))
missing_required = ' '.join(arg.options_list[0] for arg in errors)
raise CLIError('({} | {}) are required'.format(missing_required, '--ids'))
return

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


def is_homebrew():
return any((p.startswith(HOMEBREW_CELLAR_PATH) for p in sys.path))
return any(p.startswith(HOMEBREW_CELLAR_PATH) for p in sys.path)


# A workaround for https://github.com/Azure/azure-cli/issues/4428
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli-core/azure/cli/core/extension/_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get_index(index_url=None, cli_ctx=None):

for try_number in range(TRIES):
try:
response = requests.get(index_url, verify=(not should_disable_connection_verify()))
response = requests.get(index_url, verify=not should_disable_connection_verify())
if response.status_code == 200:
return response.json()
msg = ERR_TMPL_NON_200.format(response.status_code, index_url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _whl_download_from_url(url_parse_result, ext_file):
import requests
from azure.cli.core.util import should_disable_connection_verify
url = url_parse_result.geturl()
r = requests.get(url, stream=True, verify=(not should_disable_connection_verify()))
r = requests.get(url, stream=True, verify=not should_disable_connection_verify())
if r.status_code != 200:
raise CLIError("Request to {} failed with {}".format(url, r.status_code))
with open(ext_file, 'wb') as f:
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli-core/azure/cli/core/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"To learn more about extensions, please visit "
"'https://docs.microsoft.com/cli/azure/azure-cli-extensions-overview'")

OVERVIEW_REFERENCE = ("https://aka.ms/cli_ref")
OVERVIEW_REFERENCE = "https://aka.ms/cli_ref"


class IncorrectUsageError(CLIError):
Expand Down
10 changes: 5 additions & 5 deletions src/azure-cli/azure/cli/command_modules/acr/_docker_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def _handle_challenge_phase(login_server,

request_url = 'https://' + login_server + '/v2/'
logger.debug(add_timestamp("Sending a HTTP Get request to {}".format(request_url)))
challenge = requests.get(request_url, verify=(not should_disable_connection_verify()))
challenge = requests.get(request_url, verify=not should_disable_connection_verify())

if challenge.status_code != 401 or 'WWW-Authenticate' not in challenge.headers:
from ._errors import CONNECTIVITY_CHALLENGE_ERROR
Expand Down Expand Up @@ -164,7 +164,7 @@ def _get_aad_token_after_challenge(cli_ctx,

logger.debug(add_timestamp("Sending a HTTP Post request to {}".format(authhost)))
response = requests.post(authhost, urlencode(content), headers=headers,
verify=(not should_disable_connection_verify()))
verify=not should_disable_connection_verify())

if response.status_code == 429:
if is_diagnostics_context:
Expand Down Expand Up @@ -200,7 +200,7 @@ def _get_aad_token_after_challenge(cli_ctx,

logger.debug(add_timestamp("Sending a HTTP Post request to {}".format(authhost)))
response = requests.post(authhost, urlencode(content), headers=headers,
verify=(not should_disable_connection_verify()))
verify=not should_disable_connection_verify())

if response.status_code not in [200]:
from ._errors import CONNECTIVITY_ACCESS_TOKEN_ERROR
Expand Down Expand Up @@ -301,7 +301,7 @@ def _get_token_with_username_and_password(login_server,

logger.debug(add_timestamp("Sending a HTTP Post request to {}".format(authhost)))
response = requests.post(authhost, urlencode(content), headers=headers,
verify=(not should_disable_connection_verify()))
verify=not should_disable_connection_verify())

if response.status_code != 200:
from ._errors import CONNECTIVITY_ACCESS_TOKEN_ERROR
Expand Down Expand Up @@ -365,7 +365,7 @@ def _get_credentials(cmd, # pylint: disable=too-many-statements
url = 'https://' + login_server + '/v2/'
try:
logger.debug(add_timestamp("Sending a HTTP Get request to {}".format(url)))
challenge = requests.get(url, verify=(not should_disable_connection_verify()))
challenge = requests.get(url, verify=not should_disable_connection_verify())
if challenge.status_code == 403:
raise CLIError("Looks like you don't have access to registry '{}'. "
"To see configured firewall rules, run 'az acr show --query networkRuleSet --name {}'. "
Expand Down
4 changes: 2 additions & 2 deletions src/azure-cli/azure/cli/command_modules/acr/check_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def _get_registry_status(login_server, registry_name, ignore_errors):
try:
request_url = 'https://' + login_server + '/v2/'
logger.debug(add_timestamp("Sending a HTTP GET request to {}".format(request_url)))
challenge = requests.get(request_url, verify=(not should_disable_connection_verify()))
challenge = requests.get(request_url, verify=not should_disable_connection_verify())
except SSLError:
from ._errors import CONNECTIVITY_SSL_ERROR
_handle_error(CONNECTIVITY_SSL_ERROR.format_error_message(login_server), ignore_errors)
Expand Down Expand Up @@ -334,7 +334,7 @@ def _check_registry_health(cmd, registry_name, ignore_errors):
if v.client_id == client_id:
from azure.core.exceptions import HttpResponseError
try:
valid_identity = (resolve_identity_client_id(cmd.cli_ctx, k) == client_id)
valid_identity = resolve_identity_client_id(cmd.cli_ctx, k) == client_id
except HttpResponseError:
pass
if not valid_identity:
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli/azure/cli/command_modules/acr/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def acr_pack_build(cmd, # pylint: disable=too-many-locals

registry_prefixes = '$Registry/', registry.login_server + '/'
# If the image name doesn't have any required prefix, add it
if all((not image_name.startswith(prefix) for prefix in registry_prefixes)):
if all(not image_name.startswith(prefix) for prefix in registry_prefixes):
original_image_name = image_name
image_name = registry_prefixes[0] + image_name
logger.debug('Modified image name from %s to %s', original_image_name, image_name)
Expand Down
4 changes: 2 additions & 2 deletions src/azure-cli/azure/cli/command_modules/acs/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ def validate_ip_ranges(namespace):
ip_ranges = [ip.strip() for ip in namespace.api_server_authorized_ip_ranges.split(",")]

if restrict_traffic_to_agentnodes in ip_ranges and len(ip_ranges) > 1:
raise CLIError(("Setting --api-server-authorized-ip-ranges to 0.0.0.0/32 is not allowed with other IP ranges."
"Refer to https://aka.ms/aks/whitelist for more details"))
raise CLIError("Setting --api-server-authorized-ip-ranges to 0.0.0.0/32 is not allowed with other IP ranges."
"Refer to https://aka.ms/aks/whitelist for more details")

if allow_all_traffic in ip_ranges and len(ip_ranges) > 1:
raise CLIError("--api-server-authorized-ip-ranges cannot be disabled and simultaneously enabled")
Expand Down
4 changes: 2 additions & 2 deletions src/azure-cli/azure/cli/command_modules/acs/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def _aks_browse(
stderr=subprocess.STDOUT,
)
# output format: "'{port}'"
dashboard_port = int((dashboard_port.replace("'", "")))
dashboard_port = int(dashboard_port.replace("'", ""))
except subprocess.CalledProcessError as err:
raise ResourceNotFoundError('Could not find dashboard port: {} Command output: {}'.format(err, err.output))

Expand Down Expand Up @@ -473,7 +473,7 @@ def wait_then_open_async(url):
"""
Spawns a thread that waits for a bit then opens a URL.
"""
t = threading.Thread(target=wait_then_open, args=({url}))
Copy link
Member

Choose a reason for hiding this comment

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

The ({url}) is actually a set. This is wrong.

t = threading.Thread(target=wait_then_open, args=(url,))
t.daemon = True
t.start()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ def import_config(cmd,
kvs_to_write = []
kvs_to_write.extend(kv_diff.get(JsonDiff.ADD, []))
kvs_to_write.extend(ff_diff.get(JsonDiff.ADD, []))
kvs_to_write.extend((update["new"] for update in kv_diff.get(JsonDiff.UPDATE, [])))
kvs_to_write.extend((update["new"] for update in ff_diff.get(JsonDiff.UPDATE, [])))
kvs_to_write.extend(update["new"] for update in kv_diff.get(JsonDiff.UPDATE, []))
kvs_to_write.extend(update["new"] for update in ff_diff.get(JsonDiff.UPDATE, []))

# write all kvs
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def add_webapp_access_restriction(
int(subnet is not None) != 1):
err_msg = 'Please specify either: --subnet or --ip-address or --service-tag'
raise MutuallyExclusiveArgumentError(err_msg)
if (skip_service_tag_validation is not None):
if skip_service_tag_validation is not None:
logger.warning('Skipping service tag validation.')

# get rules list
Expand Down Expand Up @@ -98,7 +98,7 @@ def remove_webapp_access_restriction(cmd, resource_group_name, name, rule_name=N
if input_rule_types > 1:
err_msg = 'Please specify either: --subnet or --ip-address or --service-tag'
raise MutuallyExclusiveArgumentError(err_msg)
if (skip_service_tag_validation is not None):
if skip_service_tag_validation is not None:
logger.warning('Skipping service tag validation.')

rule_instance = None
Expand Down
30 changes: 15 additions & 15 deletions src/azure-cli/azure/cli/command_modules/appservice/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ def check_language_runtime(cmd, resource_group_name, name):
functions_version = runtime_info['functionapp_version']
if runtime and runtime_version:
if not is_flex:
runtime_helper = _FunctionAppStackRuntimeHelper(cmd=cmd, linux=is_linux, windows=(not is_linux))
runtime_helper = _FunctionAppStackRuntimeHelper(cmd=cmd, linux=is_linux, windows=not is_linux)
runtime_helper.resolve(runtime, runtime_version, functions_version, is_linux)
else:
location = app.location
Expand Down Expand Up @@ -929,9 +929,9 @@ def validate_zip_deploy_app_setting_exists(cmd, resource_group_name, name, slot=
storage_connection = str(keyval['value'])

if storage_connection is None:
raise ValidationError(('The Azure CLI does not support this deployment path. Please '
'configure the app to deploy from a remote package using the steps here: '
'https://aka.ms/deployfromurl'))
raise ValidationError('The Azure CLI does not support this deployment path. Please '
'configure the app to deploy from a remote package using the steps here: '
'https://aka.ms/deployfromurl')


def upload_zip_to_storage(cmd, resource_group_name, name, src, slot=None):
Expand Down Expand Up @@ -4239,7 +4239,7 @@ def _parse_raw_stacks(self, stacks):
for major_version in runtime['properties']['majorVersions']:
for minor_version in major_version['minorVersions']:
runtime_version = minor_version['value']
if (minor_version['stackSettings'].get('linuxRuntimeSettings') is None):
if minor_version['stackSettings'].get('linuxRuntimeSettings') is None:
continue

runtime_settings = minor_version['stackSettings']['linuxRuntimeSettings']
Expand Down Expand Up @@ -4791,7 +4791,7 @@ def create_functionapp(cmd, resource_group_name, name, storage_account, plan=Non
if functions_version is None and flexconsumption_location is None:
logger.warning("No functions version specified so defaulting to 4.")
functions_version = '4'
enable_dapr = (enable_dapr == "true")
enable_dapr = enable_dapr == "true"
if deployment_source_url and deployment_local_git:
raise MutuallyExclusiveArgumentError('usage error: --deployment-source-url <url> | --deployment-local-git')
if any([cpu, memory, workload_profile_name]) and environment is None:
Expand Down Expand Up @@ -4875,7 +4875,7 @@ def create_functionapp(cmd, resource_group_name, name, storage_account, plan=Non
if flexconsumption_location is None:
deployment_source_branch = deployment_source_branch or 'master'

disable_app_insights = (disable_app_insights == "true")
disable_app_insights = disable_app_insights == "true"

site_config = SiteConfig(app_settings=[])
client = web_client_factory(cmd.cli_ctx)
Expand Down Expand Up @@ -4992,7 +4992,7 @@ def create_functionapp(cmd, resource_group_name, name, storage_account, plan=Non
runtime_helper = _FlexFunctionAppStackRuntimeHelper(cmd, flexconsumption_location, runtime, runtime_version)
matched_runtime = runtime_helper.resolve(runtime, runtime_version)
else:
runtime_helper = _FunctionAppStackRuntimeHelper(cmd, linux=is_linux, windows=(not is_linux))
runtime_helper = _FunctionAppStackRuntimeHelper(cmd, linux=is_linux, windows=not is_linux)
matched_runtime = runtime_helper.resolve("dotnet" if not runtime else runtime,
runtime_version, functions_version, is_linux)

Expand Down Expand Up @@ -5082,10 +5082,10 @@ def create_functionapp(cmd, resource_group_name, name, storage_account, plan=Non
# validate cpu and memory parameters.
_validate_cpu_momory_functionapp(cpu, memory)

if (workload_profile_name is not None):
if workload_profile_name is not None:
functionapp_def.workload_profile_name = workload_profile_name

if (cpu is not None and memory is not None):
if cpu is not None and memory is not None:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pylint does not find this error, reported to pylint-dev/pylint#10084

functionapp_def.resource_config = ResourceConfig()
functionapp_def.resource_config.cpu = cpu
functionapp_def.resource_config.memory = memory
Expand All @@ -5105,7 +5105,7 @@ def create_functionapp(cmd, resource_group_name, name, storage_account, plan=Non
if enable_dapr:
logger.warning("Please note while using Dapr Extension for Azure Functions, app port is "
"mandatory when using Dapr triggers and should be empty when using only Dapr bindings.")
dapr_enable_api_logging = (dapr_enable_api_logging == "true")
dapr_enable_api_logging = dapr_enable_api_logging == "true"
dapr_config = DaprConfig()
dapr_config.enabled = True
dapr_config.app_id = dapr_app_id
Expand Down Expand Up @@ -8187,7 +8187,7 @@ def _remove_publish_profile_from_github(cmd, resource_group, name, repo, token,


def _runtime_supports_github_actions(cmd, runtime_string, is_linux):
helper = _StackRuntimeHelper(cmd, linux=(is_linux), windows=(not is_linux))
helper = _StackRuntimeHelper(cmd, linux=is_linux, windows=not is_linux)
matched_runtime = helper.resolve(runtime_string, is_linux)
if not matched_runtime:
return False
Expand All @@ -8203,8 +8203,8 @@ def _get_functionapp_runtime_version(cmd, location, name, resource_group, runtim
is_flex = is_flex_functionapp(cmd.cli_ctx, resource_group, name)

try:
if (not is_flex):
helper = _FunctionAppStackRuntimeHelper(cmd, linux=(is_linux), windows=(not is_linux))
if not is_flex:
helper = _FunctionAppStackRuntimeHelper(cmd, linux=is_linux, windows=not is_linux)
matched_runtime = helper.resolve(runtime_string, runtime_version, functionapp_version, is_linux)
else:
runtime_helper = _FlexFunctionAppStackRuntimeHelper(cmd, location, runtime_string, runtime_version)
Expand Down Expand Up @@ -8328,7 +8328,7 @@ def _get_functionapp_runtime_info(cmd, resource_group, name, slot, is_linux): #


def _get_app_runtime_info_helper(cmd, app_runtime, app_runtime_version, is_linux):
helper = _StackRuntimeHelper(cmd, linux=(is_linux), windows=(not is_linux))
helper = _StackRuntimeHelper(cmd, linux=is_linux, windows=not is_linux)
if not is_linux:
matched_runtime = helper.resolve("{}|{}".format(app_runtime, app_runtime_version), is_linux)
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ def test_logicapp_e2etest_logicapp_versions_e2e(self, resource_group, storage_ac
# show
result = self.cmd('logicapp config appsettings list -g {} -n {}'.format(
resource_group, logicapp_name)).get_output_in_json()
appsetting_runtime_version = next((x for x in result if x['name'] == 'WEBSITE_NODE_DEFAULT_VERSION'))
appsetting_runtime_version = next(x for x in result if x['name'] == 'WEBSITE_NODE_DEFAULT_VERSION')
self.assertEqual(appsetting_runtime_version['name'], 'WEBSITE_NODE_DEFAULT_VERSION')
self.assertEqual(appsetting_runtime_version['value'], '~16')
appsetting_functions_version = next((x for x in result if x['name'] == 'FUNCTIONS_EXTENSION_VERSION'))
appsetting_functions_version = next(x for x in result if x['name'] == 'FUNCTIONS_EXTENSION_VERSION')
self.assertEqual(appsetting_functions_version['name'], 'FUNCTIONS_EXTENSION_VERSION')
self.assertEqual(appsetting_functions_version['value'], '~4')

Expand Down Expand Up @@ -179,7 +179,7 @@ def test_logicapp_config_appsettings_e2e(self, resource_group):
# show
result = self.cmd('logicapp config appsettings list -g {} -n {}'.format(
resource_group, logicapp_name)).get_output_in_json()
s2 = next((x for x in result if x['name'] == 's2'))
s2 = next(x for x in result if x['name'] == 's2')
self.assertEqual(s2['name'], 's2')
self.assertEqual(s2['slotSetting'], False)
self.assertEqual(s2['value'], 'bar')
Expand Down
Loading