Skip to content

Commit 9b59ba5

Browse files
chore(ci): enable Ruff rule ERA001 and fix errors (#2591)
1 parent 2dd0057 commit 9b59ba5

File tree

11 files changed

+42
-43
lines changed

11 files changed

+42
-43
lines changed

aws_lambda_powertools/logging/compat.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ def findCaller(stack_info=False, stacklevel=2): # pragma: no cover
2424
## If we want to use the last (deepest) frame:
2525
break
2626
## If we want to mimic the warnings module:
27-
# return ("sys", 1, "(unknown function)", None) # noqa: E800
28-
## If we want to be pedantic: # noqa: E800
29-
# raise ValueError("call stack is not deep enough") # noqa: E800
27+
# return ("sys", 1, "(unknown function)", None) # noqa: ERA001
28+
## If we want to be pedantic: # noqa: ERA001
29+
# raise ValueError("call stack is not deep enough") # noqa: ERA001
3030
f = next_f # noqa: VNE001
3131
if not _is_internal_frame(f):
3232
stacklevel -= 1

aws_lambda_powertools/metrics/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,10 @@ def serialize_metric_set(
225225
logger.debug({"details": "Serializing metrics", "metrics": metrics, "dimensions": dimensions})
226226

227227
# For standard resolution metrics, don't add StorageResolution field to avoid unnecessary ingestion of data into cloudwatch # noqa E501
228-
# Example: [ { "Name": "metric_name", "Unit": "Count"} ] # noqa E800
228+
# Example: [ { "Name": "metric_name", "Unit": "Count"} ] # noqa ERA001
229229
#
230230
# In case using high-resolution metrics, add StorageResolution field
231-
# Example: [ { "Name": "metric_name", "Unit": "Count", "StorageResolution": 1 } ] # noqa E800
231+
# Example: [ { "Name": "metric_name", "Unit": "Count", "StorageResolution": 1 } ] # noqa ERA001
232232
metric_definition: List[MetricNameUnitResolution] = []
233233
metric_names_and_values: Dict[str, float] = {} # { "metric_name": 1.0 }
234234

aws_lambda_powertools/tracing/tracer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ async def async_tasks():
510510
functools.partial(self.capture_method, capture_response=capture_response, capture_error=capture_error),
511511
)
512512

513-
# Example: app.ClassA.get_all # noqa E800
513+
# Example: app.ClassA.get_all # noqa ERA001
514514
method_name = f"{method.__module__}.{method.__qualname__}"
515515

516516
capture_response = resolve_truthy_env_var_choice(

aws_lambda_powertools/utilities/batch/base.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,13 @@ def __call__(self, records: List[dict], handler: Callable, lambda_context: Optio
159159
#
160160
# Scenario: Injects Lambda context
161161
#
162-
# def record_handler(record, lambda_context): ... # noqa: E800
163-
# with processor(records=batch, handler=record_handler, lambda_context=context): ... # noqa: E800
162+
# def record_handler(record, lambda_context): ... # noqa: ERA001
163+
# with processor(records=batch, handler=record_handler, lambda_context=context): ... # noqa: ERA001
164164
#
165165
# Scenario: Does NOT inject Lambda context (default)
166166
#
167-
# def record_handler(record): pass # noqa: E800
168-
# with processor(records=batch, handler=record_handler): ... # noqa: E800
167+
# def record_handler(record): pass # noqa: ERA001
168+
# with processor(records=batch, handler=record_handler): ... # noqa: ERA001
169169
#
170170
if lambda_context is None:
171171
self._handler_accepts_lambda_context = False
@@ -449,7 +449,7 @@ def record_handler(record: DynamoDBRecord):
449449
logger.info(record.dynamodb.new_image)
450450
payload: dict = json.loads(record.dynamodb.new_image.get("item"))
451451
# alternatively:
452-
# changes: Dict[str, Any] = record.dynamodb.new_image # noqa: E800
452+
# changes: Dict[str, Any] = record.dynamodb.new_image # noqa: ERA001
453453
# payload = change.get("Message") -> "<payload>"
454454
...
455455
@@ -593,7 +593,7 @@ async def record_handler(record: DynamoDBRecord):
593593
logger.info(record.dynamodb.new_image)
594594
payload: dict = json.loads(record.dynamodb.new_image.get("item"))
595595
# alternatively:
596-
# changes: Dict[str, Any] = record.dynamodb.new_image # noqa: E800
596+
# changes: Dict[str, Any] = record.dynamodb.new_image # noqa: ERA001
597597
# payload = change.get("Message") -> "<payload>"
598598
...
599599

aws_lambda_powertools/utilities/jmespath_utils/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def extract_data_from_envelope(data: Union[Dict, str], envelope: str, jmespath_o
4747
4848
4949
def handler(event: dict, context: LambdaContext):
50-
# event = {"body": "{\"customerId\":\"dd4649e6-2484-4993-acb8-0f9123103394\"}"} # noqa: E800
50+
# event = {"body": "{\"customerId\":\"dd4649e6-2484-4993-acb8-0f9123103394\"}"} # noqa: ERA001
5151
payload = extract_data_from_envelope(data=event, envelope="powertools_json(body)")
5252
customer = payload.get("customerId") # now deserialized
5353
...

aws_lambda_powertools/utilities/parser/models/dynamodb.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ class DynamoDBStreamChangedRecordModel(BaseModel):
1919
# since both images are optional, they can both be None. However, at least one must
2020
# exist in a legal model of NEW_AND_OLD_IMAGES type
2121
# @root_validator
22-
# def check_one_image_exists(cls, values): # noqa: E800
23-
# new_img, old_img = values.get("NewImage"), values.get("OldImage") # noqa: E800
24-
# stream_type = values.get("StreamViewType") # noqa: E800
25-
# if stream_type == "NEW_AND_OLD_IMAGES" and not new_img and not old_img: # noqa: E800
26-
# raise TypeError("DynamoDB streams model failed validation, missing both new & old stream images") # noqa: E800,E501
27-
# return values # noqa: E800
22+
# def check_one_image_exists(cls, values): # noqa: ERA001
23+
# new_img, old_img = values.get("NewImage"), values.get("OldImage") # noqa: ERA001
24+
# stream_type = values.get("StreamViewType") # noqa: ERA001
25+
# if stream_type == "NEW_AND_OLD_IMAGES" and not new_img and not old_img: # noqa: ERA001
26+
# raise TypeError("DynamoDB streams model failed validation, missing both new & old stream images") # noqa: ERA001,E501
27+
# return values # noqa: ERA001
2828

2929

3030
class UserIdentity(BaseModel):

aws_lambda_powertools/utilities/parser/models/sqs.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,24 @@ class SqsMsgAttributeModel(BaseModel):
2929
# labels with the format .custom-data-type.
3030
# https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-message-metadata.html#sqs-message-attributes
3131
# @validator("dataType")
32-
# def valid_type(cls, v): # noqa: VNE001,E800 # noqa: E800
33-
# pattern = re.compile("Number.*|String.*|Binary.*") # noqa: E800
34-
# if not pattern.match(v): # noqa: E800
35-
# raise TypeError("data type is invalid") # noqa: E800
36-
# return v # noqa: E800
32+
# def valid_type(cls, v): # noqa: VNE001,ERA001 # noqa: ERA001
33+
# pattern = re.compile("Number.*|String.*|Binary.*") # noqa: ERA001
34+
# if not pattern.match(v): # noqa: ERA001
35+
# raise TypeError("data type is invalid") # noqa: ERA001
36+
# return v # noqa: ERA001
3737
#
3838
# # validate that dataType and value are not None and match
3939
# @root_validator
40-
# def check_str_and_binary_values(cls, values): # noqa: E800
41-
# binary_val, str_val = values.get("binaryValue", ""), values.get("stringValue", "") # noqa: E800
42-
# data_type = values.get("dataType") # noqa: E800
43-
# if not str_val and not binary_val: # noqa: E800
44-
# raise TypeError("both binaryValue and stringValue are missing") # noqa: E800
45-
# if data_type.startswith("Binary") and not binary_val: # noqa: E800
46-
# raise TypeError("binaryValue is missing") # noqa: E800
47-
# if (data_type.startswith("String") or data_type.startswith("Number")) and not str_val: # noqa: E800
48-
# raise TypeError("stringValue is missing") # noqa: E800
49-
# return values # noqa: E800
40+
# def check_str_and_binary_values(cls, values): # noqa: ERA001
41+
# binary_val, str_val = values.get("binaryValue", ""), values.get("stringValue", "") # noqa: ERA001
42+
# data_type = values.get("dataType") # noqa: ERA001
43+
# if not str_val and not binary_val: # noqa: ERA001
44+
# raise TypeError("both binaryValue and stringValue are missing") # noqa: ERA001
45+
# if data_type.startswith("Binary") and not binary_val: # noqa: ERA001
46+
# raise TypeError("binaryValue is missing") # noqa: ERA001
47+
# if (data_type.startswith("String") or data_type.startswith("Number")) and not str_val: # noqa: ERA001
48+
# raise TypeError("stringValue is missing") # noqa: ERA001
49+
# return values # noqa: ERA001
5050

5151

5252
class SqsRecordModel(BaseModel):

examples/idempotency/tests/test_with_dynamodb_local.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_idempotent_lambda(lambda_context):
2626
app_test_dynamodb_local.persistence_layer.client = dynamodb_local_client
2727

2828
# If desired, you can use a different DynamoDB Local table name than what your code already uses
29-
# app.persistence_layer.table_name = "another table name" # noqa: E800
29+
# app.persistence_layer.table_name = "another table name" # noqa: ERA001
3030

3131
result = app_test_dynamodb_local.handler({"testkey": "testvalue"}, lambda_context)
3232
assert result["payment_id"] == 12345

poetry.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ruff.toml

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +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-
"ERA001", # Found commented-out code - disabled temporarily
4140
"PLW", # Warning category - disabled temporarily
4241
"PLR", # Refactoring category - disabled temporarily
4342
"PLC", # Convention category - disabled temporarily

tests/functional/event_handler/test_api_gateway.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -923,17 +923,17 @@ def test_similar_dynamic_routes():
923923
event = deepcopy(LOAD_GW_EVENT)
924924

925925
# WHEN
926-
# r'^/accounts/(?P<account_id>\\w+\\b)$' # noqa: E800
926+
# r'^/accounts/(?P<account_id>\\w+\\b)$' # noqa: ERA001
927927
@app.get("/accounts/<account_id>")
928928
def get_account(account_id: str):
929929
assert account_id == "single_account"
930930

931-
# r'^/accounts/(?P<account_id>\\w+\\b)/source_networks$' # noqa: E800
931+
# r'^/accounts/(?P<account_id>\\w+\\b)/source_networks$' # noqa: ERA001
932932
@app.get("/accounts/<account_id>/source_networks")
933933
def get_account_networks(account_id: str):
934934
assert account_id == "nested_account"
935935

936-
# r'^/accounts/(?P<account_id>\\w+\\b)/source_networks/(?P<network_id>\\w+\\b)$' # noqa: E800
936+
# r'^/accounts/(?P<account_id>\\w+\\b)/source_networks/(?P<network_id>\\w+\\b)$' # noqa: ERA001
937937
@app.get("/accounts/<account_id>/source_networks/<network_id>")
938938
def get_network_account(account_id: str, network_id: str):
939939
assert account_id == "nested_account"
@@ -959,17 +959,17 @@ def test_similar_dynamic_routes_with_whitespaces():
959959
event = deepcopy(LOAD_GW_EVENT)
960960

961961
# WHEN
962-
# r'^/accounts/(?P<account_id>\\w+\\b)$' # noqa: E800
962+
# r'^/accounts/(?P<account_id>\\w+\\b)$' # noqa: ERA001
963963
@app.get("/accounts/<account_id>")
964964
def get_account(account_id: str):
965965
assert account_id == "single account"
966966

967-
# r'^/accounts/(?P<account_id>\\w+\\b)/source_networks$' # noqa: E800
967+
# r'^/accounts/(?P<account_id>\\w+\\b)/source_networks$' # noqa: ERA001
968968
@app.get("/accounts/<account_id>/source_networks")
969969
def get_account_networks(account_id: str):
970970
assert account_id == "nested account"
971971

972-
# r'^/accounts/(?P<account_id>\\w+\\b)/source_networks/(?P<network_id>\\w+\\b)$' # noqa: E800
972+
# r'^/accounts/(?P<account_id>\\w+\\b)/source_networks/(?P<network_id>\\w+\\b)$' # noqa: ERA001
973973
@app.get("/accounts/<account_id>/source_networks/<network_id>")
974974
def get_network_account(account_id: str, network_id: str):
975975
assert account_id == "nested account"

0 commit comments

Comments
 (0)