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 unnecessary-dunder-call #30365

Merged
merged 10 commits into from
Dec 11, 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
1 change: 0 additions & 1 deletion pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ disable=
consider-using-enumerate,
# These rules were added in Pylint >= 2.12, disable them to avoid making retroactive change
missing-timeout,
unnecessary-dunder-call,
# These rules were added in Pylint >= 3.2
possibly-used-before-assignment,

Expand Down
2 changes: 1 addition & 1 deletion scripts/live_test/generate_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def render(data, container, container_url, testdata, USER_REPO, USER_BRANCH, COM
# elif 'sequential' in name:
# display_name = 'sequential'
try:
html = requests.get(url).content.__str__()
html = requests.get(url).text
pattern = re.compile('\\d+ tests ran in')
match = pattern.search(html)
number = match.group().split()[0]
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli-core/azure/cli/core/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def flush():
save(get_config_dir(), _session.generate_payload())

# reset session fields, retaining correlation id and application
_session.__init__(correlation_id=_session.correlation_id, application=_session.application)
_session.__init__(correlation_id=_session.correlation_id, application=_session.application) # pylint: disable=unnecessary-dunder-call
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It uses __init__ to reset fields, so weird.

Copy link
Member

Choose a reason for hiding this comment

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

@evelyn-ys for awareness.

Copy link
Member

@evelyn-ys evelyn-ys Dec 11, 2024

Choose a reason for hiding this comment

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

I don't know why the original author write in this way. Maybe we can try replace with

_session = TelemetrySession(correlation_id=_session.correlation_id, application=_session.application)



@_user_agrees_to_telemetry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ def test_list_staticsite_secrets(self):

self.staticapp_client.list_static_site_secrets.assert_called_once_with(resource_group_name=self.rg1, name=self.name1)
from ast import literal_eval
self.assertEqual(literal_eval(secret.__str__())["properties"]["apiKey"], "key")
self.assertEqual(literal_eval(str(secret))["properties"]["apiKey"], "key")


def test_staticsite_identity_assign(self):
Expand Down Expand Up @@ -656,7 +656,7 @@ def test_reset_staticsite_api_key(self):
self.staticapp_client.reset_static_site_api_key.assert_called_once()

from ast import literal_eval
reset_envelope = literal_eval(self.staticapp_client.reset_static_site_api_key.call_args[1]["reset_properties_envelope"].__str__())
reset_envelope = literal_eval(str(self.staticapp_client.reset_static_site_api_key.call_args[1]["reset_properties_envelope"]))
self.assertEqual(reset_envelope["repository_token"], self.token1)

@mock.patch("azure.cli.command_modules.appservice.static_sites.show_app")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,23 +481,23 @@ def test_botservice_create_should_raise_error_for_invalid_app_id_args(self, reso
self.cmd('az bot create -g {rg} -n {botname} --appid {numbers_id} --app-type MultiTenant')
raise AssertionError()
except CLIError as cli_error:
assert cli_error.__str__() == expected_error
assert str(cli_error) == expected_error
except AssertionError:
raise AssertionError('should have thrown an error for appid that is not valid GUID.')

try:
self.cmd('az bot create -g {rg} -n {botname} --appid {short_app_id} --app-type MultiTenant')
raise AssertionError()
except CLIError as cli_error:
assert cli_error.__str__() == expected_error
assert str(cli_error) == expected_error
except AssertionError:
raise AssertionError('should have thrown an error for appid that is not valid GUID.')

try:
self.cmd('az bot create -g {rg} -n {botname} --appid "" --app-type MultiTenant')
raise AssertionError()
except CLIError as cli_error:
assert cli_error.__str__() == expected_error
assert str(cli_error) == expected_error
except AssertionError:
raise AssertionError('should have thrown an error for appid that is not valid GUID.')

Expand Down Expand Up @@ -527,7 +527,7 @@ def test_botservice_should_throw_if_name_is_unavailable(self, resource_group):
'az bot create -g {rg2} -n {botname} -d {description} -e {endpoint} --appid {app_id} --app-type MultiTenant')
raise AssertionError()
except CLIError as cli_error:
assert cli_error.__str__().startswith('Unable to create bot.\nReason: ')
assert str(cli_error).startswith('Unable to create bot.\nReason: ')
except AssertionError:
raise AssertionError('should have thrown an error for unavailable name.')

Expand Down Expand Up @@ -780,8 +780,8 @@ def test_botservice_prepare_deploy_should_fail_if_code_dir_doesnt_exist(self):
prepare_webapp_deploy(language, code_dir, proj_file_path)
raise Exception("'az bot prepare-publish' should have failed with nonexistent --code-dir value")
except CLIError as cli_error:
print(cli_error.__str__())
assert cli_error.__str__() == 'Provided --code-dir value (does_not_exist) does not exist'
print(str(cli_error))
assert str(cli_error) == 'Provided --code-dir value (does_not_exist) does not exist'
except Exception as error:
raise error

Expand All @@ -794,7 +794,7 @@ def test_botservice_prepare_deploy_javascript_should_fail_with_proj_file_path(se
prepare_webapp_deploy(language, code_dir, proj_file_path)
raise Exception("'az bot prepare-publish ' should have failed with --proj-file-path")
except CLIError as cli_error:
assert cli_error.__str__() == '--proj-file-path should not be passed in if language is not Csharp'
assert str(cli_error) == '--proj-file-path should not be passed in if language is not Csharp'
except Exception as error:
raise error

Expand All @@ -820,7 +820,7 @@ def test_botservice_prepare_deploy_typescript_should_fail_with_proj_file_path(se
prepare_webapp_deploy(language, code_dir, proj_file_path)
raise Exception("'az bot prepare-publish --lang Typescript' should have failed with --proj-file-path")
except CLIError as cli_error:
assert cli_error.__str__() == '--proj-file-path should not be passed in if language is not Csharp'
assert str(cli_error) == '--proj-file-path should not be passed in if language is not Csharp'

def test_botservice_prepare_deploy_typescript(self):
code_dir = 'node_bot_typescript'
Expand Down Expand Up @@ -880,7 +880,7 @@ def test_botservice_prepare_deploy_csharp_no_proj_file(self):
prepare_webapp_deploy(language, code_dir, proj_file_path)
raise Exception("'az bot prepare-publish ' should have failed with no --proj-file-path")
except CLIError as cli_error:
assert cli_error.__str__() == '--proj-file-path must be provided if language is Csharp'
assert str(cli_error) == '--proj-file-path must be provided if language is Csharp'

def test_botservice_prepare_deploy_csharp_fail_if_deployment_file_exists(self):
code_dir = 'csharp_bot_deployment'
Expand All @@ -899,7 +899,7 @@ def test_botservice_prepare_deploy_csharp_fail_if_deployment_file_exists(self):
shutil.rmtree(code_dir)
except CLIError as cli_error:
shutil.rmtree(code_dir)
assert cli_error.__str__() == '.deployment found in csharp_bot_deployment\nPlease delete this .deployment before ' \
assert str(cli_error) == '.deployment found in csharp_bot_deployment\nPlease delete this .deployment before ' \
'calling "az bot prepare-deploy"'
except Exception as error:
shutil.rmtree(code_dir)
Expand All @@ -921,7 +921,7 @@ def test_botservice_prepare_deploy_javascript_fail_if_web_config_exists(self):
shutil.rmtree(code_dir)
except CLIError as cli_error:
shutil.rmtree(code_dir)
assert cli_error.__str__() == 'web.config found in node_bot_web_config\nPlease delete this web.config before ' \
assert str(cli_error) == 'web.config found in node_bot_web_config\nPlease delete this web.config before ' \
'calling "az bot prepare-deploy"'
except Exception as error:
shutil.rmtree(code_dir)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,7 @@ def set_managed_identity(cmd, resource_group_name, containerapp_def, system_assi
containerapp_def["identity"] = {}
containerapp_def["identity"]["type"] = "None"

if assign_system_identity and containerapp_def["identity"]["type"].__contains__("SystemAssigned"):
if assign_system_identity and "SystemAssigned" in containerapp_def["identity"]["type"]:
logger.warning("System identity is already assigned to containerapp")

# Assign correct type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def test_load_cert_file(self):
try:
blob, thumbprint = load_cert_file(pfx_file, testpassword)
except CLIInternalError as e:
self.assertTrue(e.error_msg.error_msg.__contains__('Invalid password or PKCS12 data'))
self.assertIn('Invalid password or PKCS12 data', e.error_msg.error_msg)
self.assertEqual('', thumbprint)

pfx_file = os.path.join(TEST_DIR, 'data', 'cert2.pfx')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def prepare_containerapp_env_for_app_e2e_tests(test_cls):
try:
managed_env = test_cls.cmd('containerapp env show -g {} -n {}'.format(rg_name, env_name)).get_output_in_json()
except CLIInternalError as e:
if e.error_msg.__contains__('ResourceGroupNotFound') or e.error_msg.__contains__('ResourceNotFound'):
if 'ResourceGroupNotFound' in e.error_msg or 'ResourceNotFound' in e.error_msg:
test_cls.cmd(f'group create -n {rg_name}')
test_cls.cmd(f'containerapp env create -g {rg_name} -n {env_name} --logs-destination none')
managed_env = test_cls.cmd('containerapp env show -g {} -n {}'.format(rg_name, env_name)).get_output_in_json()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def _validate_deployment_name_with_template_specs(namespace):
namespace.template_spec = namespace.template_spec.strip("\"")
if not is_valid_resource_id(namespace.template_spec):
raise CLIError('--template-spec is not a valid resource ID.')
if namespace.template_spec.__contains__("versions") is False:
if 'versions' not in namespace.template_spec:
raise CLIError('Please enter a valid template spec version ID.')
template_filename = parse_resource_id(namespace.template_spec).get('resource_name')
if template_filename:
Expand Down