Skip to content

Commit f816cf9

Browse files
authored
chore: Enable pyupgrade check (#3019)
1 parent 04fcfe0 commit f816cf9

File tree

62 files changed

+178
-168
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+178
-168
lines changed

bin/_file_formatter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def config_additional_args(cls) -> None: # noqa: empty-method-without-abstract-
4545
"""Optionally configure additional args to arg parser."""
4646

4747
def process_file(self, file_path: str) -> None:
48-
with open(file_path, "r", encoding="utf-8") as f:
48+
with open(file_path, encoding="utf-8") as f:
4949
file_str = f.read()
5050
try:
5151
formatted_file_str = self.format_str(file_str)

bin/add_transform_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def replace_aws_partition(partition: str, file_path: str) -> None:
7575
def generate_transform_test_output_files(input_file_path: str, file_basename: str) -> None:
7676
output_file_option = file_basename + ".json"
7777

78-
with open(os.path.join(input_file_path), "r") as f:
78+
with open(os.path.join(input_file_path)) as f:
7979
manifest = yaml_parse(f) # type: ignore[no-untyped-call]
8080

8181
transform_test_output_paths = {

bin/sam-translate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def package(input_file_path, output_file_path): # type: ignore[no-untyped-def]
102102

103103

104104
def transform_template(input_file_path, output_file_path): # type: ignore[no-untyped-def]
105-
with open(input_file_path, "r") as f:
105+
with open(input_file_path) as f:
106106
sam_template = yaml_parse(f) # type: ignore[no-untyped-call]
107107

108108
try:

integration/combination/test_api_with_authorizer_apikey.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def verify_authorized_request(
8585
status = response.status_code
8686
if status != expected_status_code:
8787
raise StatusCodeError(
88-
"Request to {} failed with status: {}, expected status: {}".format(url, status, expected_status_code)
88+
f"Request to {url} failed with status: {status}, expected status: {expected_status_code}"
8989
)
9090

9191
if not header_key or not header_value:

integration/combination/test_api_with_authorizers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ def verify_authorized_request(
444444

445445
if status != expected_status_code:
446446
raise StatusCodeError(
447-
"Request to {} failed with status: {}, expected status: {}".format(url, status, expected_status_code)
447+
f"Request to {url} failed with status: {status}, expected status: {expected_status_code}"
448448
)
449449

450450
if not header_key or not header_value:

integration/combination/test_function_with_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ def test_function_with_api(self):
2828

2929
self.assertTrue(
3030
get_api_policy_expectation in policy,
31-
"{} should be present in policy {}".format(get_api_policy_expectation, policy),
31+
f"{get_api_policy_expectation} should be present in policy {policy}",
3232
)
3333
self.assertTrue(
3434
post_api_policy_expectation in policy,
35-
"{} should be present in policy {}".format(post_api_policy_expectation, policy),
35+
f"{post_api_policy_expectation} should be present in policy {policy}",
3636
)

integration/combination/test_intrinsic_function_support.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ def test_severless_api_properties_support(self):
5353

5454
self.assertTrue(
5555
get_api_policy_expectation in policy,
56-
"{} should be present in policy {}".format(get_api_policy_expectation, policy),
56+
f"{get_api_policy_expectation} should be present in policy {policy}",
5757
)
5858
self.assertTrue(
5959
post_api_policy_expectation in policy,
60-
"{} should be present in policy {}".format(post_api_policy_expectation, policy),
60+
f"{post_api_policy_expectation} should be present in policy {policy}",
6161
)
6262

6363
# Test for tags

integration/conftest.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,16 @@ def upload_resources(get_s3):
171171

172172
def get_s3_uri(file_name, uri_type, bucket, region):
173173
if uri_type == "s3":
174-
return "s3://{}/{}".format(bucket, file_name)
174+
return f"s3://{bucket}/{file_name}"
175175

176176
if region == "us-east-1":
177-
return "https://s3.amazonaws.com/{}/{}".format(bucket, file_name)
177+
return f"https://s3.amazonaws.com/{bucket}/{file_name}"
178178
if region == "us-iso-east-1":
179-
return "https://s3.us-iso-east-1.c2s.ic.gov/{}/{}".format(bucket, file_name)
179+
return f"https://s3.us-iso-east-1.c2s.ic.gov/{bucket}/{file_name}"
180180
if region == "us-isob-east-1":
181-
return "https://s3.us-isob-east-1.sc2s.sgov.gov/{}/{}".format(bucket, file_name)
181+
return f"https://s3.us-isob-east-1.sc2s.sgov.gov/{bucket}/{file_name}"
182182

183-
return "https://s3-{}.amazonaws.com/{}/{}".format(region, bucket, file_name)
183+
return f"https://s3-{region}.amazonaws.com/{bucket}/{file_name}"
184184

185185

186186
@pytest.fixture()

integration/helpers/base_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ def _fill_template(self, folder, file_name):
416416
data = f.read()
417417
for key, _ in self.code_key_to_file.items():
418418
# We must double the {} to escape them so they will survive a round of unescape
419-
data = data.replace("${{{}}}".format(key), self.get_code_key_s3_uri(key))
419+
data = data.replace(f"${{{key}}}", self.get_code_key_s3_uri(key))
420420
yaml_doc = yaml_parse(data)
421421

422422
dump_yaml(updated_template_path, yaml_doc)

integration/helpers/deployer/deployer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def create_changeset(
140140
"ChangeSetType": changeset_type,
141141
"Parameters": parameter_values,
142142
"Capabilities": capabilities,
143-
"Description": "Created by SAM CLI at {0} UTC".format(datetime.utcnow().isoformat()),
143+
"Description": f"Created by SAM CLI at {datetime.utcnow().isoformat()} UTC",
144144
"Tags": tags,
145145
}
146146

@@ -172,7 +172,7 @@ def _create_change_set(self, stack_name, changeset_type, **kwargs):
172172
except botocore.exceptions.ClientError as ex:
173173
if "The bucket you are attempting to access must be addressed using the specified endpoint" in str(ex):
174174
raise deploy_exceptions.DeployBucketInDifferentRegionError(
175-
"Failed to create/update stack {}".format(stack_name)
175+
f"Failed to create/update stack {stack_name}"
176176
)
177177
raise deploy_exceptions.ChangeSetError(stack_name=stack_name, msg=str(ex))
178178

@@ -278,7 +278,7 @@ def wait_for_changeset(self, changeset_id, stack_name):
278278
raise deploy_exceptions.ChangeEmptyError(stack_name=stack_name)
279279

280280
raise deploy_exceptions.ChangeSetError(
281-
stack_name=stack_name, msg="ex: {0} Status: {1}. Reason: {2}".format(ex, status, reason)
281+
stack_name=stack_name, msg=f"ex: {ex} Status: {status}. Reason: {reason}"
282282
)
283283

284284
def execute_changeset(self, changeset_id, stack_name):
@@ -323,7 +323,7 @@ def wait_for_execute(self, stack_name, changeset_type):
323323
elif changeset_type == "UPDATE":
324324
waiter = self._client.get_waiter("stack_update_complete")
325325
else:
326-
raise RuntimeError("Invalid changeset type {0}".format(changeset_type))
326+
raise RuntimeError(f"Invalid changeset type {changeset_type}")
327327

328328
# Poll every 30 seconds. Polling too frequently risks hitting rate limits
329329
# on CloudFormation's DescribeStacks API
@@ -408,7 +408,7 @@ def get_stack_outputs(self, stack_name, echo=True):
408408
try:
409409
outputs = stacks_description["Stacks"][0]["Outputs"]
410410
if echo:
411-
sys.stdout.write("\nStack {stack_name} outputs:\n".format(stack_name=stack_name))
411+
sys.stdout.write(f"\nStack {stack_name} outputs:\n")
412412
sys.stdout.flush()
413413
self._display_stack_outputs(stack_outputs=outputs)
414414
return outputs

0 commit comments

Comments
 (0)