Skip to content

Commit 3d64789

Browse files
committed
chore: fmt and linting
1 parent f63cadc commit 3d64789

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

aws_lambda_powertools/utilities/batch/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
"""
66

77
from aws_lambda_powertools.utilities.batch.base import (
8-
BasePartialProcessor,
8+
AsyncBatchProcessor,
99
BasePartialBatchProcessor,
10+
BasePartialProcessor,
1011
BatchProcessor,
11-
AsyncBatchProcessor,
1212
EventType,
1313
FailureResponse,
1414
SuccessResponse,
15-
batch_processor,
1615
async_batch_processor,
16+
batch_processor,
1717
)
1818
from aws_lambda_powertools.utilities.batch.exceptions import ExceptionInfo
1919

aws_lambda_powertools/utilities/batch/base.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,18 @@
1111
import sys
1212
from abc import ABC, abstractmethod
1313
from enum import Enum
14-
from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union, overload, Awaitable
14+
from typing import (
15+
Any,
16+
Awaitable,
17+
Callable,
18+
Dict,
19+
List,
20+
Optional,
21+
Tuple,
22+
Type,
23+
Union,
24+
overload,
25+
)
1526

1627
from aws_lambda_powertools.middleware_factory import lambda_handler_decorator
1728
from aws_lambda_powertools.utilities.batch.exceptions import (
@@ -118,7 +129,7 @@ async def async_process():
118129
return list(await asyncio.gather(*[self._async_process_record(record) for record in self.records]))
119130

120131
# WARNING
121-
# Do not use "asyncio.run(async_process())" due to Lambda container thaws/freeze, otherwise we might get "Event Loop is closed"
132+
# Do not use "asyncio.run(async_process())" due to Lambda container thaws/freeze, otherwise we might get "Event Loop is closed" # noqa: E501
122133
# Instead, get_event_loop() can also create one if a previous was erroneously closed
123134
# More: https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtime-environment.html#runtimes-lifecycle-shutdown
124135
# Extra: just follow how the well-tested mangum library do:
@@ -127,7 +138,7 @@ async def async_process():
127138

128139
# Detect environment and create a loop for each one
129140
coro = async_process()
130-
if os.environ.get('AWS_LAMBDA_RUNTIME_API'):
141+
if os.environ.get("AWS_LAMBDA_RUNTIME_API"):
131142
# Running in lambda server
132143
loop = asyncio.get_event_loop()
133144
task_instance = loop.create_task(coro)
@@ -393,7 +404,7 @@ def _clean(self):
393404
if self._entire_batch_failed():
394405
raise BatchProcessingError(
395406
msg=f"All records failed processing. {len(self.exceptions)} individual errors logged "
396-
f"separately below.",
407+
f"separately below.",
397408
child_exceptions=self.exceptions,
398409
)
399410

@@ -480,7 +491,7 @@ def _process_record(self, record: dict) -> Union[SuccessResponse, FailureRespons
480491

481492
@lambda_handler_decorator
482493
def batch_processor(
483-
handler: Callable, event: Dict, context: LambdaContext, record_handler: Callable, processor: BatchProcessor
494+
handler: Callable, event: Dict, context: LambdaContext, record_handler: Callable, processor: BatchProcessor
484495
):
485496
"""
486497
Middleware to handle batch event processing
@@ -524,7 +535,6 @@ def batch_processor(
524535

525536

526537
class AsyncBatchProcessor(BasePartialBatchProcessor):
527-
528538
def _process_record(self, record: dict):
529539
raise NotImplementedError()
530540

@@ -551,7 +561,11 @@ async def _async_process_record(self, record: dict) -> Union[SuccessResponse, Fa
551561

552562
@lambda_handler_decorator
553563
def async_batch_processor(
554-
handler: Callable, event: Dict, context: LambdaContext, record_handler: Callable[..., Awaitable[Any]], processor: AsyncBatchProcessor
564+
handler: Callable,
565+
event: Dict,
566+
context: LambdaContext,
567+
record_handler: Callable[..., Awaitable[Any]],
568+
processor: AsyncBatchProcessor,
555569
):
556570
"""
557571
Middleware to handle batch event processing

tests/functional/test_utilities_batch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import json
22
from random import randint
3-
from typing import Callable, Dict, Optional, Awaitable, Any
3+
from typing import Any, Awaitable, Callable, Dict, Optional
44

55
import pytest
66
from botocore.config import Config
77

88
from aws_lambda_powertools.utilities.batch import (
9-
BatchProcessor,
109
AsyncBatchProcessor,
10+
BatchProcessor,
1111
EventType,
12-
batch_processor,
1312
async_batch_processor,
13+
batch_processor,
1414
)
1515
from aws_lambda_powertools.utilities.batch.exceptions import BatchProcessingError
1616
from aws_lambda_powertools.utilities.data_classes.dynamo_db_stream_event import (

0 commit comments

Comments
 (0)