Skip to content

Commit 6e1ff98

Browse files
{CI} Fix all style errors for pylint 4.x compatibility (#33347)
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent a26c9ce commit 6e1ff98

8 files changed

Lines changed: 18 additions & 70 deletions

File tree

src/azure-cli-core/azure/cli/core/util.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,11 +576,10 @@ def get_file_yaml(file_path, throw_on_empty=True):
576576

577577

578578
def read_file_content(file_path, allow_binary=False):
579-
from codecs import open as codecs_open
580579
# Note, always put 'utf-8-sig' first, so that BOM in WinOS won't cause trouble.
581580
for encoding in ['utf-8-sig', 'utf-8', 'utf-16', 'utf-16le', 'utf-16be']:
582581
try:
583-
with codecs_open(file_path, encoding=encoding) as f:
582+
with open(file_path, mode='r', encoding=encoding) as f:
584583
logger.debug("attempting to read file %s as %s", file_path, encoding)
585584
return f.read()
586585
except (UnicodeError, UnicodeDecodeError):

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from azure.cli.core.util import sdk_no_wait
2828
from azure.cli.core.util import get_logger
2929
from azure.cli.core.azclierror import (RequiredArgumentMissingError, MutuallyExclusiveArgumentError,
30-
InvalidArgumentValueError)
30+
InvalidArgumentValueError, CLIError)
3131
from azure.mgmt.apimanagement.models import (ApiManagementServiceResource, ApiManagementServiceIdentity,
3232
ApiManagementServiceSkuProperties,
3333
ApiManagementServiceBackupRestoreParameters,
@@ -555,11 +555,13 @@ def apim_api_export(client, resource_group_name, service_name, api_id, export_fo
555555

556556
# Obtain link from the response
557557
response_dict = api_export_result_to_dict(response)
558+
link = None
558559
try:
559560
# Extract the link from the response where results are stored
560561
link = response_dict['additional_properties']['properties']['value']['link']
561562
except KeyError:
562563
logger.warning("Error exporting api from APIManagement. The expected link is not present in the response.")
564+
raise CLIError("Failed to export API: link not found in response")
563565

564566
# Determine the file extension based on the mappedFormat
565567
if mappedFormat in ['swagger-link', 'openapi+json-link']:
@@ -577,12 +579,15 @@ def apim_api_export(client, resource_group_name, service_name, api_id, export_fo
577579
full_path = os.path.join(file_path, file_name)
578580

579581
# Get the results from the link where the API Export Results are stored
582+
exportedResults = None
580583
try:
581584
exportedResults = requests.get(link, timeout=30)
582585
if not exportedResults.ok:
583-
logger.warning("Got bad status from APIManagement during API Export:%s, {exportedResults.status_code}")
586+
logger.warning("Got bad status from APIManagement during API Export: %s", exportedResults.status_code)
587+
raise CLIError(f"Failed to export API: Got status code {exportedResults.status_code}")
584588
except requests.exceptions.ReadTimeout:
585589
logger.warning("Timed out while exporting api from APIManagement.")
590+
raise CLIError("Failed to export API: Request timed out")
586591

587592
try:
588593
# Try to parse as JSON

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
retryable_method,
6767
raise_missing_token_suggestion,
6868
_get_location_from_resource_group,
69-
_list_app,
7069
is_functionapp,
7170
is_linux_webapp,
7271
_rename_server_farm_props,

src/azure-cli/azure/cli/command_modules/batch/_command_type.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -756,10 +756,11 @@ def get_track1_rest_names(self, cls):
756756
def _resolve_track1_type_hint(self, type_hint):
757757
"""Resolve type hints to the legacy track1 type string format."""
758758
args = get_args(type_hint)
759+
none_type = None.__class__
759760

760761
# Optional[T] / Union[..., None] -> select the best non-None candidate.
761-
if type(None) in args:
762-
non_none_args = [arg for arg in args if arg is not type(None)]
762+
if none_type in args:
763+
non_none_args = [arg for arg in args if arg is not none_type]
763764
preferred_args = [arg for arg in non_none_args if arg != str] or non_none_args
764765
selected = preferred_args[0] if preferred_args else type_hint
765766
return self.convert_to_track1_type(str(selected))

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def __prepare_configuration_file(cmd, resource_group_name, kudu_client, folder_p
5959
if setting['name'] not in ignorable_settings}
6060
existing = None
6161
if not os.path.exists(app_settings_path):
62-
logger.info('App settings not found at %s, defaulting app settings to {}.', app_settings_path)
62+
logger.info('App settings not found at %s, defaulting app settings to empty.', app_settings_path)
6363
existing = {}
6464
else:
6565
with open(app_settings_path, 'r') as f:
@@ -271,7 +271,10 @@ def download_app(cmd, client, resource_group_name, resource_name, file_save_path
271271
if (os.path.exists(os.path.join(folder_path, 'PostDeployScripts', 'deploy.cmd.template')) and
272272
os.path.exists(os.path.join(folder_path, 'deploy.cmd'))):
273273

274-
logger.info('Post deployment scripts and deploy.cmd found in source under folder %s. Copying deploy.cmd.')
274+
logger.info(
275+
'Post deployment scripts and deploy.cmd found in source under folder %s. Copying deploy.cmd.',
276+
folder_path
277+
)
275278

276279
shutil.copyfile(os.path.join(folder_path, 'deploy.cmd'),
277280
os.path.join(folder_path, 'PostDeployScripts', 'deploy.cmd.template'))
@@ -318,8 +321,8 @@ def download_app(cmd, client, resource_group_name, resource_name, file_save_path
318321
existing = None
319322
if not os.path.exists(app_settings_path):
320323

321-
logger.info('App settings not found at %s, defaulting app settings to {}.', app_settings_path)
322-
existing = '{}'
324+
logger.info('App settings not found at %s, defaulting app settings to empty.', app_settings_path)
325+
existing = {}
323326
else:
324327
with open(app_settings_path, 'r') as f:
325328
existing = json.load(f)

src/azure-cli/azure/cli/command_modules/containerapp/_utils.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -895,23 +895,6 @@ def _remove_env_vars(existing_env_vars, remove_env_vars):
895895
logger.warning("Environment variable {} does not exist.".format(old_env_var)) # pylint: disable=logging-format-interpolation
896896

897897

898-
def _remove_env_vars(existing_env_vars, remove_env_vars):
899-
for old_env_var in remove_env_vars:
900-
901-
# Check if updating existing env var
902-
is_existing = False
903-
for index, value in enumerate(existing_env_vars):
904-
existing_env_var = value
905-
if existing_env_var["name"].lower() == old_env_var.lower():
906-
is_existing = True
907-
existing_env_vars.pop(index)
908-
break
909-
910-
# If not updating existing env var, add it as a new env var
911-
if not is_existing:
912-
logger.warning("Environment variable {} does not exist.".format(old_env_var)) # pylint: disable=logging-format-interpolation
913-
914-
915898
def _add_or_update_tags(containerapp_def, tags):
916899
if 'tags' not in containerapp_def:
917900
if tags:

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2784,13 +2784,6 @@ def cli_cosmosdb_managed_cassandra_datacenter_update(client,
27842784
return client.begin_create_update(resource_group_name, cluster_name, data_center_name, data_center_resource)
27852785

27862786

2787-
def _handle_exists_exception(http_response_error):
2788-
2789-
if http_response_error.status_code == 404:
2790-
return False
2791-
raise http_response_error
2792-
2793-
27942787
def process_restorable_databases(restorable_databases, database_name):
27952788

27962789
latest_database_delete_time = datetime.datetime.utcfromtimestamp(0)

src/azure-cli/azure/cli/command_modules/synapse/manual/operations/sqlpoolblobauditingpolicy.py

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -861,41 +861,6 @@ def _audit_policy_validate_arguments(
861861
raise CLIError('event-hub-authorization-rule-id must be specified if event-hub-target-state is enabled')
862862

863863

864-
def _get_diagnostic_settings_url(
865-
cmd,
866-
resource_group_name,
867-
workspace_name,
868-
sql_pool_name=None):
869-
870-
from azure.cli.core.commands.client_factory import get_subscription_id
871-
872-
diag_settings = '/subscriptions/{}/resourceGroups/{}/providers/Microsoft.Synapse/workspaces/{}'.format(
873-
get_subscription_id(cmd.cli_ctx),
874-
resource_group_name, workspace_name)
875-
876-
if sql_pool_name is not None:
877-
diag_settings = diag_settings + '/sqlpools/{}'.format(sql_pool_name)
878-
879-
return diag_settings
880-
881-
882-
def _get_diagnostic_settings(
883-
cmd,
884-
resource_group_name,
885-
workspace_name,
886-
sql_pool_name=None):
887-
'''
888-
Common code to get server or database diagnostic settings
889-
'''
890-
891-
diagnostic_settings_url = _get_diagnostic_settings_url(
892-
cmd=cmd, resource_group_name=resource_group_name,
893-
workspace_name=workspace_name, sql_pool_name=sql_pool_name)
894-
azure_monitor_client = cf_monitor(cmd.cli_ctx)
895-
896-
return list(azure_monitor_client.diagnostic_settings.list(diagnostic_settings_url))
897-
898-
899864
def workspace_audit_policy_show(
900865
cmd,
901866
client,

0 commit comments

Comments
 (0)