Skip to content

chore(ci): enable Ruff rules PLW, PLR, PLC and PLE and fix the errors #2593

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

Merged
merged 2 commits into from
Jun 27, 2023
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
6 changes: 4 additions & 2 deletions aws_lambda_powertools/event_handler/api_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,12 +843,14 @@ def include_router(self, router: "Router", prefix: Optional[str] = None) -> None
router.context = self.context

for route, func in router._routes.items():
new_route = route

if prefix:
rule = route[0]
rule = prefix if rule == "/" else f"{prefix}{rule}"
route = (rule, *route[1:])
new_route = (rule, *route[1:])

self.route(*route)(func)
self.route(*new_route)(func)


class Router(BaseRouter):
Expand Down
2 changes: 1 addition & 1 deletion aws_lambda_powertools/metrics/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def __init__(self, service: Optional[str] = None, namespace: Optional[str] = Non
self.dimension_set = self._dimensions

self.dimension_set.update(**self._default_dimensions)
return super().__init__(
super().__init__(
namespace=namespace,
service=service,
metric_set=self.metric_set,
Expand Down
3 changes: 2 additions & 1 deletion examples/parameters/tests/test_clear_cache_global.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
import src.app as app

from src import app

from aws_lambda_powertools.utilities import parameters

Expand Down
3 changes: 2 additions & 1 deletion examples/parameters/tests/test_clear_cache_method.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
import src.app as app

from src import app


@pytest.fixture(scope="function", autouse=True)
Expand Down
2 changes: 1 addition & 1 deletion examples/parameters/tests/test_single_mock.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import src.single_mock as single_mock
from src import single_mock


def test_handler(monkeypatch):
Expand Down
3 changes: 2 additions & 1 deletion examples/parameters/tests/test_with_fixture.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
import src.single_mock as single_mock

from src import single_mock


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion examples/parameters/tests/test_with_monkeypatch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from unittest.mock import patch

import src.single_mock as single_mock
from src import single_mock


# Replaces "aws_lambda_powertools.utilities.parameters.get_parameter" with a Mock object
Expand Down
4 changes: 0 additions & 4 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ ignore = [
"B018", # useless-expression - disabled temporarily
"COM812", # Trailing comma missing - disabled temporarily
"PLC1901", # Compare-to-empty-string - disabled temporarily
"PLW", # Warning category - disabled temporarily
"PLR", # Refactoring category - disabled temporarily
"PLC", # Convention category - disabled temporarily
"PLE", # Error category - disabled temporarily
"ISC", # flake8-implicit-str-concat - disabled temporarily
"I001", # isort - disabled temporarily
]
Expand Down
20 changes: 10 additions & 10 deletions tests/e2e/event_handler/test_header_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ def test_alb_headers_serializer(alb_basic_listener_endpoint):
# Only the last header should be set
for key, value in headers.items():
assert key in response.headers
value = value if isinstance(value, str) else sorted(value)[-1]
assert response.headers[key] == value
new_value = value if isinstance(value, str) else sorted(value)[-1]
assert response.headers[key] == new_value

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

for key, value in headers.items():
assert key in response.headers
value = value if isinstance(value, str) else ", ".join(sorted(value))
new_value = value if isinstance(value, str) else ", ".join(sorted(value))

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

for cookie in cookies:
assert cookie.name in response.cookies
Expand Down Expand Up @@ -143,8 +143,8 @@ def test_api_gateway_rest_headers_serializer(apigw_rest_endpoint):

for key, value in headers.items():
assert key in response.headers
value = value if isinstance(value, str) else ", ".join(sorted(value))
assert response.headers[key] == value
new_value = value if isinstance(value, str) else ", ".join(sorted(value))
assert response.headers[key] == new_value

for cookie in cookies:
assert cookie.name in response.cookies
Expand Down Expand Up @@ -180,8 +180,8 @@ def test_api_gateway_http_headers_serializer(apigw_http_endpoint):

for key, value in headers.items():
assert key in response.headers
value = value if isinstance(value, str) else ", ".join(sorted(value))
assert response.headers[key] == value
new_value = value if isinstance(value, str) else ", ".join(sorted(value))
assert response.headers[key] == new_value

for cookie in cookies:
assert cookie.name in response.cookies
Expand Down Expand Up @@ -217,8 +217,8 @@ def test_lambda_function_url_headers_serializer(lambda_function_url_endpoint):

for key, value in headers.items():
assert key in response.headers
value = value if isinstance(value, str) else ", ".join(sorted(value))
assert response.headers[key] == value
new_value = value if isinstance(value, str) else ", ".join(sorted(value))
assert response.headers[key] == new_value

for cookie in cookies:
assert cookie.name in response.cookies
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/utils/data_fetcher/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Optional, Tuple

import boto3
import requests as requests
import requests
from mypy_boto3_lambda import LambdaClient
from mypy_boto3_lambda.type_defs import InvocationResponseTypeDef
from requests import Request, Response
Expand Down