Skip to content

Commit bdd164e

Browse files
authored
chore: Upgrade ruff to 0.0.259 and enable C4 rules (#3066)
1 parent 422a638 commit bdd164e

File tree

8 files changed

+10
-9
lines changed

8 files changed

+10
-9
lines changed

bin/sam-translate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def transform_template(input_file_path, output_file_path): # type: ignore[no-un
116116
except InvalidDocumentException as e:
117117
error_message = reduce(lambda message, error: message + " " + error.message, e.causes, e.message)
118118
LOG.error(error_message)
119-
errors = map(lambda cause: cause.message, e.causes)
119+
errors = (cause.message for cause in e.causes)
120120
LOG.error(errors)
121121

122122

requirements/dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pytest-xdist>=2.5,<4
44
pytest-env>=0.6,<1
55
pytest-rerunfailures>=9.1,<12
66
pyyaml~=6.0
7-
ruff==0.0.254 # loose the requirement once it is more stable
7+
ruff==0.0.259 # loose the requirement once it is more stable
88

99
# Test requirements
1010
pytest>=6.2,<8

ruff.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ select = [
2020
"RUF", # Ruff-specific rules
2121
"YTT", # flake8-2020
2222
"UP", # pyupgrade
23+
"C4", # flake8-comprehensions
2324
]
2425

2526
# Mininal python version we support is 3.7

samtranslator/metrics/metrics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def _flush_metrics(self, namespace, metrics): # type: ignore[no-untyped-def]
5959
"""
6060
Internal method to publish all provided metrics to cloudwatch, please make sure that array size of metrics is <= 20.
6161
"""
62-
metric_data = list(map(lambda m: m.get_metric_data(), metrics)) # type: ignore[no-any-return]
62+
metric_data = [m.get_metric_data() for m in metrics]
6363
try:
6464
if metric_data:
6565
self.cloudwatch_client.put_metric_data(Namespace=namespace, MetricData=metric_data)

samtranslator/model/update_policy.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ def to_dict(self) -> Dict[str, Dict[str, Any]]:
2727
:return: a dict that can be used as part of a cloudformation template
2828
"""
2929
dict_with_nones = self._asdict()
30-
codedeploy_lambda_alias_update_dict = dict(
30+
codedeploy_lambda_alias_update_dict = {
3131
# Type ignore next line. `ref(None)` is not a typical usage of `ref()`.
32-
(k, v)
32+
k: v
3333
for k, v in dict_with_nones.items()
3434
if v != ref(None) and v is not None # type: ignore
35-
)
35+
}
3636
return {"CodeDeployLambdaAliasUpdate": codedeploy_lambda_alias_update_dict}

samtranslator/plugins/api/implicit_api_plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ def _add_combined_condition_to_template(self, template_dict, condition_name, con
371371
raise ValueError("conditions_to_combine must have at least 2 conditions")
372372

373373
template_conditions = template_dict.setdefault("Conditions", {})
374-
new_template_conditions = make_combined_condition(sorted(list(conditions_to_combine)), condition_name)
374+
new_template_conditions = make_combined_condition(sorted(conditions_to_combine), condition_name)
375375
# make_combined_condition() won't return None if `conditions_to_combine` has at least 2 elements,
376376
# which is checked above.
377377
# TODO: refactor the code to make the length check in one place only.

samtranslator/swagger/swagger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ def set_path_default_apikey_required(self, path: str, required_options_api_key:
622622
"""
623623

624624
for method_name, method_definition in self.iter_on_all_methods_for_path(path): # type: ignore[no-untyped-call]
625-
apikey_security_names = set(["api_key", "api_key_false"])
625+
apikey_security_names = {"api_key", "api_key_false"}
626626
existing_non_apikey_security = []
627627
existing_apikey_security = []
628628
apikey_security = []

samtranslator/translator/managed_policy_translator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def _load_policies_from_iam(self) -> None:
2828
name_to_arn_map: Dict[str, str] = {}
2929

3030
for page in page_iterator:
31-
name_to_arn_map.update(map(lambda x: (x["PolicyName"], x["Arn"]), page["Policies"]))
31+
name_to_arn_map.update((x["PolicyName"], x["Arn"]) for x in page["Policies"])
3232

3333
LOG.info("Finished loading policies from IAM.")
3434
self._policy_map = name_to_arn_map

0 commit comments

Comments
 (0)