1
1
from __future__ import annotations
2
2
3
3
import io
4
- from typing import (
5
- IO ,
6
- TYPE_CHECKING ,
7
- Any ,
8
- Iterable ,
9
- List ,
10
- Literal ,
11
- Optional ,
12
- Sequence ,
13
- TypeVar ,
14
- Union ,
15
- cast ,
16
- overload ,
17
- )
4
+ from typing import IO , TYPE_CHECKING , Any , Iterable , Literal , Sequence , TypeVar , cast , overload
18
5
19
6
from aws_lambda_powertools .utilities .streaming ._s3_seekable_io import _S3SeekableIO
20
7
from aws_lambda_powertools .utilities .streaming .transformations import (
21
8
CsvTransform ,
22
9
GzipTransform ,
23
10
)
24
- from aws_lambda_powertools .utilities .streaming .transformations .base import (
25
- BaseTransform ,
26
- T ,
27
- )
11
+ from aws_lambda_powertools .utilities .streaming .transformations .base import T
28
12
29
13
if TYPE_CHECKING :
30
14
from mmap import mmap
31
15
32
16
from mypy_boto3_s3 .client import S3Client
33
17
18
+ from aws_lambda_powertools .utilities .streaming .transformations .base import BaseTransform
19
+
34
20
_CData = TypeVar ("_CData" )
35
21
36
22
@@ -74,10 +60,10 @@ def __init__(
74
60
self ,
75
61
bucket : str ,
76
62
key : str ,
77
- version_id : Optional [ str ] = None ,
78
- boto3_client : Optional [ S3Client ] = None ,
79
- is_gzip : Optional [ bool ] = False ,
80
- is_csv : Optional [ bool ] = False ,
63
+ version_id : str | None = None ,
64
+ boto3_client : S3Client | None = None ,
65
+ is_gzip : bool | None = False ,
66
+ is_csv : bool | None = False ,
81
67
** sdk_options ,
82
68
):
83
69
self .bucket = bucket
@@ -94,14 +80,14 @@ def __init__(
94
80
)
95
81
96
82
# Stores the list of data transformations
97
- self ._data_transformations : List [BaseTransform ] = []
83
+ self ._data_transformations : list [BaseTransform ] = []
98
84
if is_gzip :
99
85
self ._data_transformations .append (GzipTransform ())
100
86
if is_csv :
101
87
self ._data_transformations .append (CsvTransform ())
102
88
103
89
# Stores the cached transformed stream
104
- self ._transformed_stream : Optional [ IO [bytes ]] = None
90
+ self ._transformed_stream : IO [bytes ] | None = None
105
91
106
92
@property
107
93
def size (self ) -> int :
@@ -152,8 +138,8 @@ def transform(self, transformations: BaseTransform[T] | Sequence[BaseTransform[T
152
138
def transform (
153
139
self ,
154
140
transformations : BaseTransform [T ] | Sequence [BaseTransform [T ]],
155
- in_place : Optional [ bool ] = False ,
156
- ) -> Optional [ T ] :
141
+ in_place : bool | None = False ,
142
+ ) -> T | None :
157
143
"""
158
144
Applies one or more data transformations to the stream.
159
145
@@ -241,10 +227,10 @@ def close(self):
241
227
def read (self , size : int = - 1 ) -> bytes :
242
228
return self .transformed_stream .read (size )
243
229
244
- def readline (self , size : Optional [ int ] = - 1 ) -> bytes :
230
+ def readline (self , size : int | None = - 1 ) -> bytes :
245
231
return self .transformed_stream .readline ()
246
232
247
- def readlines (self , hint : int = - 1 ) -> List [bytes ]:
233
+ def readlines (self , hint : int = - 1 ) -> list [bytes ]:
248
234
return self .transformed_stream .readlines (hint )
249
235
250
236
def __next__ (self ):
@@ -262,14 +248,14 @@ def flush(self) -> None:
262
248
def isatty (self ) -> bool :
263
249
return False
264
250
265
- def truncate (self , size : Optional [ int ] = 0 ) -> int :
251
+ def truncate (self , size : int | None = 0 ) -> int :
266
252
raise NotImplementedError ("this stream is not writable" )
267
253
268
- def write (self , data : Union [ bytes , Union [ bytearray , memoryview , Sequence [Any ], " mmap" , " _CData" ]] ) -> int :
254
+ def write (self , data : bytes | bytearray | memoryview | Sequence [Any ] | mmap | _CData ) -> int :
269
255
raise NotImplementedError ("this stream is not writable" )
270
256
271
257
def writelines (
272
258
self ,
273
- data : Iterable [Union [ bytes , Union [ bytearray , memoryview , Sequence [Any ], " mmap" , " _CData" ]] ],
259
+ data : Iterable [bytes | bytearray | memoryview | Sequence [Any ] | mmap | _CData ],
274
260
) -> None :
275
261
raise NotImplementedError ("this stream is not writable" )
0 commit comments