Skip to content

Commit c4f3746

Browse files
authored
chore: Upgrade ruff to 0.4.5 (#3603)
1 parent 308d9ce commit c4f3746

File tree

14 files changed

+42
-43
lines changed

14 files changed

+42
-43
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ black-check:
5050
make format-check
5151

5252
lint:
53-
ruff samtranslator bin schema_source integration tests
53+
ruff check samtranslator bin schema_source integration tests
5454
# mypy performs type check
5555
mypy --strict samtranslator bin schema_source
5656
# cfn-lint to make sure generated CloudFormation makes sense
5757
bin/run_cfn_lint.sh
5858

5959
lint-fix:
60-
ruff --fix samtranslator bin schema_source integration tests
60+
ruff check --fix samtranslator bin schema_source integration tests
6161

6262
prepare-companion-stack:
6363
pytest -v --no-cov integration/setup -m setup

integration/ruff.toml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# black formatter takes care of the line length
22
line-length = 999
33

4+
# Mininal python version we support is 3.8
5+
target-version = "py38"
6+
47
# The code quality of tests can be a bit lower compared to samtranslator
5-
select = [
8+
lint.select = [
69
"E", # Pyflakes
710
"F", # Pyflakes
811
"PL", # pylint
@@ -15,10 +18,7 @@ select = [
1518
"UP", # pyupgrade
1619
]
1720

18-
# Mininal python version we support is 3.8
19-
target-version = "py38"
20-
21-
[per-file-ignores]
21+
[lint.per-file-ignores]
2222

2323
# The code quality of tests can be a bit lower:
2424
"**/*.py" = [

requirements/dev.txt

+1-1
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.1.0
7+
ruff~=0.4.5
88

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

ruff.toml

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# black formatter takes care of the line length
22
line-length = 999
33

4-
select = [
4+
# Mininal python version we support is 3.8
5+
target-version = "py38"
6+
7+
lint.select = [
58
"E", # pycodestyle
69
"W", # pycodestyle
710
"F", # Pyflakes
@@ -27,7 +30,7 @@ select = [
2730
"T20", # flake8-print
2831
]
2932

30-
ignore = [
33+
lint.ignore = [
3134
"UP006", # https://github.com/charliermarsh/ruff/pull/4427
3235
"UP007", # https://github.com/charliermarsh/ruff/pull/4427
3336
# Mutable class attributes should be annotated with `typing.ClassVar`
@@ -37,10 +40,7 @@ ignore = [
3740
"G004",
3841
]
3942

40-
# Mininal python version we support is 3.8
41-
target-version = "py38"
42-
43-
[per-file-ignores]
43+
[lint.per-file-ignores]
4444
# python scripts in bin/ needs some python path configurations before import
4545
"bin/*.py" = [
4646
# E402: module-import-not-at-top-of-file
@@ -53,5 +53,5 @@ target-version = "py38"
5353
"T201",
5454
]
5555

56-
[pylint]
56+
[lint.pylint]
5757
max-args = 6 # We have many functions reaching 6 args

samtranslator/model/api/http_api_generator.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -633,8 +633,7 @@ def _get_authorizers(
633633
if "OpenIdConnectUrl" in authorizer:
634634
raise InvalidResourceException(
635635
self.logical_id,
636-
"'OpenIdConnectUrl' is no longer a supported property for authorizer '%s'. Please refer to the AWS SAM documentation."
637-
% (authorizer_name),
636+
f"'OpenIdConnectUrl' is no longer a supported property for authorizer '{authorizer_name}'. Please refer to the AWS SAM documentation.",
638637
)
639638
authorizers[authorizer_name] = ApiGatewayV2Authorizer( # type: ignore[no-untyped-call]
640639
api_logical_id=self.logical_id,

samtranslator/model/eventsources/push.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ def _depend_on_lambda_permissions_using_tag(
429429
dependency, so CloudFormation will automatically wait once it reaches that function, the same
430430
as if you were using a DependsOn.
431431
"""
432-
properties = bucket.get("Properties", None)
432+
properties = bucket.get("Properties")
433433
if properties is None:
434434
properties = {}
435435
bucket["Properties"] = properties
@@ -576,14 +576,14 @@ def to_cloudformation(self, **kwargs): # type: ignore[no-untyped-def]
576576
sqs_subscription: Dict[str, Any] = sam_expect(
577577
self.SqsSubscription, self.relative_id, "SqsSubscription", is_sam_event=True
578578
).to_be_a_map()
579-
queue_arn = sqs_subscription.get("QueueArn", None)
580-
queue_url = sqs_subscription.get("QueueUrl", None)
579+
queue_arn = sqs_subscription.get("QueueArn")
580+
queue_url = sqs_subscription.get("QueueUrl")
581581
if not queue_arn or not queue_url:
582582
raise InvalidEventException(self.relative_id, "No QueueARN or QueueURL provided.")
583583

584-
queue_policy_logical_id = sqs_subscription.get("QueuePolicyLogicalId", None)
585-
batch_size = sqs_subscription.get("BatchSize", None)
586-
enabled = sqs_subscription.get("Enabled", None)
584+
queue_policy_logical_id = sqs_subscription.get("QueuePolicyLogicalId")
585+
batch_size = sqs_subscription.get("BatchSize")
586+
enabled = sqs_subscription.get("Enabled")
587587

588588
queue_policy = self._inject_sqs_queue_policy( # type: ignore[no-untyped-call]
589589
self.Topic, queue_arn, queue_url, function, queue_policy_logical_id

samtranslator/model/intrinsics.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ def make_shorthand(intrinsic_dict: Dict[str, Any]) -> str:
130130
:raises NotImplementedError: For intrinsic functions that don't support shorthands.
131131
"""
132132
if "Ref" in intrinsic_dict:
133-
return "${%s}" % intrinsic_dict["Ref"]
133+
return "${{{}}}".format(intrinsic_dict["Ref"])
134134
if "Fn::GetAtt" in intrinsic_dict:
135-
return "${%s}" % ".".join(intrinsic_dict["Fn::GetAtt"])
135+
return "${{{}}}".format(".".join(intrinsic_dict["Fn::GetAtt"]))
136136
raise NotImplementedError("Shorthanding is only supported for Ref and Fn::GetAtt")
137137

138138

samtranslator/model/sam_resources.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def resources_to_link(self, resources: Dict[str, Any]) -> Dict[str, Any]:
253253
raise InvalidResourceException(self.logical_id, e.message) from e
254254

255255
@cw_timer
256-
def to_cloudformation(self, **kwargs): # type: ignore[no-untyped-def] # noqa: PLR0912, PLR0915
256+
def to_cloudformation(self, **kwargs): # type: ignore[no-untyped-def] # noqa: PLR0915
257257
"""Returns the Lambda function, role, and event resources to which this SAM Function corresponds.
258258
259259
:param dict kwargs: already-converted resources that may need to be modified when converting this \
@@ -1914,7 +1914,7 @@ def to_cloudformation(self, **kwargs: Any) -> List[Resource]:
19141914

19151915
raise InvalidResourceException(self.logical_id, "'Destination' is an empty list")
19161916

1917-
def generate_resources( # noqa: PLR0912
1917+
def generate_resources(
19181918
self,
19191919
source: ConnectorResourceReference,
19201920
destination: ConnectorResourceReference,

samtranslator/sdk/parameter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def add_default_parameter_values(self, sam_template: Dict[str, Any]) -> Any:
5555
:return dict: Merged parameter values
5656
"""
5757

58-
parameter_definition = sam_template.get("Parameters", None)
58+
parameter_definition = sam_template.get("Parameters")
5959
if not parameter_definition or not isinstance(parameter_definition, dict):
6060
return self.parameter_values
6161

samtranslator/sdk/resource.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ def __init__(self, resource_dict: Dict[str, Any]) -> None:
2424

2525
self.resource_dict = resource_dict
2626
self.type = resource_dict.get("Type")
27-
self.condition = resource_dict.get("Condition", None)
28-
self.deletion_policy = resource_dict.get("DeletionPolicy", None)
29-
self.update_replace_policy = resource_dict.get("UpdateReplacePolicy", None)
30-
self.ignore_globals: Optional[Union[str, List[str]]] = resource_dict.get("IgnoreGlobals", None)
27+
self.condition = resource_dict.get("Condition")
28+
self.deletion_policy = resource_dict.get("DeletionPolicy")
29+
self.update_replace_policy = resource_dict.get("UpdateReplacePolicy")
30+
self.ignore_globals: Optional[Union[str, List[str]]] = resource_dict.get("IgnoreGlobals")
3131

3232
# Properties is *not* required. Ex: SimpleTable resource has no required properties
3333
self.properties = resource_dict.get("Properties", {})

samtranslator/third_party/py27hash/hash.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def hash(value): # type: ignore[no-untyped-def]
5353
if isinstance(value, int):
5454
return hash(value)
5555

56-
raise TypeError("unhashable type: '%s'" % (type(value).__name__))
56+
raise TypeError(f"unhashable type: '{type(value).__name__}'")
5757

5858
@staticmethod
5959
def thash(value): # type: ignore[no-untyped-def]

samtranslator/utils/py27hash_fix.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -506,14 +506,14 @@ def __str__(self) -> str:
506506
for i, key in enumerate(self):
507507
string += ", " if i > 0 else ""
508508
if isinstance(key, ("".__class__, bytes)):
509-
string += "%s: " % key.__repr__()
509+
string += f"{key.__repr__()}: "
510510
else:
511-
string += "%s: " % key
511+
string += f"{key}: "
512512

513513
if isinstance(self[key], ("".__class__, bytes)):
514-
string += "%s" % self[key].__repr__()
514+
string += str(self[key].__repr__())
515515
else:
516-
string += "%s" % self[key]
516+
string += str(self[key])
517517

518518
string += "}"
519519
return string

tests/model/api/test_http_api_generator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def test_auth_iam_not_enabled_with_unsupported_values(self):
170170
}
171171
self.kwargs["definition_body"] = OpenApiEditor.gen_skeleton()
172172
http_api = HttpApiGenerator(**self.kwargs)._construct_http_api()
173-
self.assertNotIn("components", http_api.Body, "EnableIamAuthorizer value: %s" % val)
173+
self.assertNotIn("components", http_api.Body, f"EnableIamAuthorizer value: {val}")
174174

175175
def test_auth_novalue_default_does_not_raise(self):
176176
self.kwargs["auth"] = self.authorizers

tests/ruff.toml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# black formatter takes care of the line length
22
line-length = 999
33

4+
# Mininal python version we support is 3.8
5+
target-version = "py38"
6+
47
# The code quality of tests can be a bit lower compared to samtranslator
5-
select = [
8+
lint.select = [
69
"E", # Pyflakes
710
"F", # Pyflakes
811
"PL", # pylint
@@ -15,10 +18,7 @@ select = [
1518
"UP", # pyupgrade
1619
]
1720

18-
# Mininal python version we support is 3.8
19-
target-version = "py38"
20-
21-
[per-file-ignores]
21+
[lint.per-file-ignores]
2222

2323
# The code quality of tests can be a bit lower:
2424
"**/*.py" = [

0 commit comments

Comments
 (0)