Skip to content

Commit 7de31cc

Browse files
refactor(streaming): use standard collections for types (#6483)
* Using generics types * Adding shared
1 parent 17b46f4 commit 7de31cc

14 files changed

+37
-10
lines changed

aws_lambda_powertools/shared/dynamodb_deserializer.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from __future__ import annotations
22

33
from decimal import Clamped, Context, Decimal, Inexact, Overflow, Rounded, Underflow
4-
from typing import Any, Callable, Sequence
4+
from typing import TYPE_CHECKING, Any
5+
6+
if TYPE_CHECKING:
7+
from collections.abc import Callable, Sequence
58

69
# NOTE: DynamoDB supports up to 38 digits precision
710
# Therefore, this ensures our Decimal follows what's stored in the table

aws_lambda_powertools/shared/functions.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
import warnings
99
from binascii import Error as BinAsciiError
1010
from pathlib import Path
11-
from typing import Any, Generator, overload
11+
from typing import TYPE_CHECKING, Any, overload
1212

1313
from aws_lambda_powertools.shared import constants
1414

15+
if TYPE_CHECKING:
16+
from collections.abc import Generator
17+
1518
logger = logging.getLogger(__name__)
1619

1720

aws_lambda_powertools/shared/types.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
from typing import Any, Callable, TypeVar
1+
from collections.abc import Callable
2+
from typing import Any, TypeVar
23

3-
AnyCallableT = TypeVar("AnyCallableT", bound=Callable[..., Any]) # noqa: VNE001
4+
AnyCallableT = TypeVar("AnyCallableT", bound=Callable[..., Any])

aws_lambda_powertools/utilities/serialization.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import base64
44
import json
5-
from typing import Any, Callable
5+
from collections.abc import Callable
6+
from typing import Any
67

78

89
def base64_encode(data: str) -> str:

aws_lambda_powertools/utilities/streaming/_s3_seekable_io.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import io
44
import logging
5-
from typing import IO, TYPE_CHECKING, Any, Iterable, Sequence, TypeVar, cast
5+
from typing import IO, TYPE_CHECKING, Any, TypeVar, cast
66

77
import boto3
88

@@ -11,6 +11,7 @@
1111
from aws_lambda_powertools.utilities.streaming.constants import MESSAGE_STREAM_NOT_WRITABLE
1212

1313
if TYPE_CHECKING:
14+
from collections.abc import Iterable, Sequence
1415
from mmap import mmap
1516

1617
from mypy_boto3_s3.client import S3Client

aws_lambda_powertools/utilities/streaming/s3_object.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from __future__ import annotations
22

33
import io
4-
from typing import IO, TYPE_CHECKING, Any, Iterable, Literal, Sequence, TypeVar, cast, overload
4+
from collections.abc import Sequence
5+
from typing import IO, TYPE_CHECKING, Any, Literal, TypeVar, cast, overload
56

67
from aws_lambda_powertools.utilities.streaming._s3_seekable_io import _S3SeekableIO
78
from aws_lambda_powertools.utilities.streaming.constants import MESSAGE_STREAM_NOT_WRITABLE
@@ -12,6 +13,7 @@
1213
from aws_lambda_powertools.utilities.streaming.types import T
1314

1415
if TYPE_CHECKING:
16+
from collections.abc import Iterable
1517
from mmap import mmap
1618

1719
from mypy_boto3_s3.client import S3Client

tests/functional/streaming/_boto3/test_s3_object.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from csv import DictReader
24
from gzip import GzipFile
35

tests/functional/streaming/_boto3/test_s3_seekable_io.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import io
24

35
import boto3

tests/unit/shared/test_dynamodb_deserializer.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from typing import Any, Dict, Optional
1+
from __future__ import annotations
2+
3+
from typing import Any
24

35
import pytest
46

@@ -10,14 +12,14 @@ def __init__(self, data: dict):
1012
self._data = data
1113
self._deserializer = TypeDeserializer()
1214

13-
def _deserialize_dynamodb_dict(self) -> Optional[Dict[str, Any]]:
15+
def _deserialize_dynamodb_dict(self) -> dict[str, Any] | None:
1416
if self._data is None:
1517
return None
1618

1719
return {k: self._deserializer.deserialize(v) for k, v in self._data.items()}
1820

1921
@property
20-
def data(self) -> Optional[Dict[str, Any]]:
22+
def data(self) -> dict[str, Any] | None:
2123
"""The primary key attribute(s) for the DynamoDB item that was modified."""
2224
return self._deserialize_dynamodb_dict()
2325

tests/unit/test_cookie_class.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from datetime import datetime
24

35
from aws_lambda_powertools.shared.cookies import Cookie, SameSite

tests/unit/test_data_classes.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import base64
24
import datetime
35
import json

tests/unit/test_json_encoder.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import decimal
24
import json
35
from dataclasses import dataclass

tests/unit/test_lru_cache.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import random
24
import sys
35

tests/unit/test_shared_functions.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import os
24
import warnings
35
from dataclasses import dataclass

0 commit comments

Comments
 (0)