Skip to content

Commit f0f38bf

Browse files
leandrodamascenarubenfonseca
authored andcommitted
chore(ci): enable Ruff rules PLW, PLR, PLC and PLE and fix the errors (aws-powertools#2593)
Co-authored-by: Ruben Fonseca <[email protected]>
1 parent c4c76f6 commit f0f38bf

File tree

10 files changed

+24
-23
lines changed

10 files changed

+24
-23
lines changed

aws_lambda_powertools/event_handler/api_gateway.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -843,12 +843,14 @@ def include_router(self, router: "Router", prefix: Optional[str] = None) -> None
843843
router.context = self.context
844844

845845
for route, func in router._routes.items():
846+
new_route = route
847+
846848
if prefix:
847849
rule = route[0]
848850
rule = prefix if rule == "/" else f"{prefix}{rule}"
849-
route = (rule, *route[1:])
851+
new_route = (rule, *route[1:])
850852

851-
self.route(*route)(func)
853+
self.route(*new_route)(func)
852854

853855

854856
class Router(BaseRouter):

aws_lambda_powertools/metrics/metrics.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def __init__(self, service: Optional[str] = None, namespace: Optional[str] = Non
7676
self.dimension_set = self._dimensions
7777

7878
self.dimension_set.update(**self._default_dimensions)
79-
return super().__init__(
79+
super().__init__(
8080
namespace=namespace,
8181
service=service,
8282
metric_set=self.metric_set,

examples/parameters/tests/test_clear_cache_global.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
2-
import src.app as app
2+
3+
from src import app
34

45
from aws_lambda_powertools.utilities import parameters
56

examples/parameters/tests/test_clear_cache_method.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
2-
import src.app as app
2+
3+
from src import app
34

45

56
@pytest.fixture(scope="function", autouse=True)

examples/parameters/tests/test_single_mock.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import src.single_mock as single_mock
1+
from src import single_mock
22

33

44
def test_handler(monkeypatch):

examples/parameters/tests/test_with_fixture.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
2-
import src.single_mock as single_mock
2+
3+
from src import single_mock
34

45

56
@pytest.fixture

examples/parameters/tests/test_with_monkeypatch.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from unittest.mock import patch
22

3-
import src.single_mock as single_mock
3+
from src import single_mock
44

55

66
# Replaces "aws_lambda_powertools.utilities.parameters.get_parameter" with a Mock object

ruff.toml

-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ ignore = [
3737
"B018", # useless-expression - disabled temporarily
3838
"COM812", # Trailing comma missing - disabled temporarily
3939
"PLC1901", # Compare-to-empty-string - disabled temporarily
40-
"PLW", # Warning category - disabled temporarily
41-
"PLR", # Refactoring category - disabled temporarily
42-
"PLC", # Convention category - disabled temporarily
43-
"PLE", # Error category - disabled temporarily
4440
"ISC", # flake8-implicit-str-concat - disabled temporarily
4541
"I001", # isort - disabled temporarily
4642
]

tests/e2e/event_handler/test_header_serializer.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ def test_alb_headers_serializer(alb_basic_listener_endpoint):
6767
# Only the last header should be set
6868
for key, value in headers.items():
6969
assert key in response.headers
70-
value = value if isinstance(value, str) else sorted(value)[-1]
71-
assert response.headers[key] == value
70+
new_value = value if isinstance(value, str) else sorted(value)[-1]
71+
assert response.headers[key] == new_value
7272

7373
# Only the last cookie should be set
7474
assert len(response.cookies.items()) == 1
@@ -104,11 +104,11 @@ def test_alb_multi_value_headers_serializer(alb_multi_value_header_listener_endp
104104

105105
for key, value in headers.items():
106106
assert key in response.headers
107-
value = value if isinstance(value, str) else ", ".join(sorted(value))
107+
new_value = value if isinstance(value, str) else ", ".join(sorted(value))
108108

109109
# ALB sorts the header values randomly, so we have to re-order them for comparison here
110110
returned_value = ", ".join(sorted(response.headers[key].split(", ")))
111-
assert returned_value == value
111+
assert returned_value == new_value
112112

113113
for cookie in cookies:
114114
assert cookie.name in response.cookies
@@ -143,8 +143,8 @@ def test_api_gateway_rest_headers_serializer(apigw_rest_endpoint):
143143

144144
for key, value in headers.items():
145145
assert key in response.headers
146-
value = value if isinstance(value, str) else ", ".join(sorted(value))
147-
assert response.headers[key] == value
146+
new_value = value if isinstance(value, str) else ", ".join(sorted(value))
147+
assert response.headers[key] == new_value
148148

149149
for cookie in cookies:
150150
assert cookie.name in response.cookies
@@ -180,8 +180,8 @@ def test_api_gateway_http_headers_serializer(apigw_http_endpoint):
180180

181181
for key, value in headers.items():
182182
assert key in response.headers
183-
value = value if isinstance(value, str) else ", ".join(sorted(value))
184-
assert response.headers[key] == value
183+
new_value = value if isinstance(value, str) else ", ".join(sorted(value))
184+
assert response.headers[key] == new_value
185185

186186
for cookie in cookies:
187187
assert cookie.name in response.cookies
@@ -217,8 +217,8 @@ def test_lambda_function_url_headers_serializer(lambda_function_url_endpoint):
217217

218218
for key, value in headers.items():
219219
assert key in response.headers
220-
value = value if isinstance(value, str) else ", ".join(sorted(value))
221-
assert response.headers[key] == value
220+
new_value = value if isinstance(value, str) else ", ".join(sorted(value))
221+
assert response.headers[key] == new_value
222222

223223
for cookie in cookies:
224224
assert cookie.name in response.cookies

tests/e2e/utils/data_fetcher/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Optional, Tuple
33

44
import boto3
5-
import requests as requests
5+
import requests
66
from mypy_boto3_lambda import LambdaClient
77
from mypy_boto3_lambda.type_defs import InvocationResponseTypeDef
88
from requests import Request, Response

0 commit comments

Comments
 (0)