11import asyncio
22import logging
3- from async_timeout import timeout
3+ import time
4+ from typing import Optional , Any , Dict , List , Union
5+
6+ from .timeout_compat import timeout
47from aiobotocore .session import AioSession
58from asyncio import CancelledError
69from botocore .exceptions import ClientError
710from botocore .config import Config
8- import time
911
1012from . import exceptions
1113
1517class Base :
1618 def __init__ (
1719 self ,
18- stream_name ,
19- session = None ,
20- endpoint_url = None ,
21- region_name = None ,
22- retry_limit = None ,
23- expo_backoff = None ,
24- expo_backoff_limit = 120 ,
25- skip_describe_stream = False ,
26- create_stream = False ,
27- create_stream_shards = 1 ,
28- ):
29-
30- self .stream_name = stream_name
20+ stream_name : str ,
21+ session : Optional [ AioSession ] = None ,
22+ endpoint_url : Optional [ str ] = None ,
23+ region_name : Optional [ str ] = None ,
24+ retry_limit : Optional [ int ] = None ,
25+ expo_backoff : Optional [ float ] = None ,
26+ expo_backoff_limit : int = 120 ,
27+ skip_describe_stream : bool = False ,
28+ create_stream : bool = False ,
29+ create_stream_shards : int = 1 ,
30+ ) -> None :
31+
32+ self .stream_name : str = stream_name
3133
3234 if session :
3335 assert isinstance (session , AioSession )
34- self .session = session
36+ self .session : AioSession = session
3537 else :
3638 self .session = AioSession ()
3739
38- self .endpoint_url = endpoint_url
39- self .region_name = region_name
40+ self .endpoint_url : Optional [ str ] = endpoint_url
41+ self .region_name : Optional [ str ] = region_name
4042
41- self .client = None
42- self .shards = None
43+ self .client : Optional [ Any ] = None # aiobotocore client
44+ self .shards : Optional [ List [ Dict [ str , Any ]]] = None
4345
44- self .stream_status = None
46+ self .stream_status : Optional [ str ] = None
4547
46- self .retry_limit = retry_limit
47- self .expo_backoff = expo_backoff
48- self .expo_backoff_limit = expo_backoff_limit
48+ self .retry_limit : Optional [ int ] = retry_limit
49+ self .expo_backoff : Optional [ float ] = expo_backoff
50+ self .expo_backoff_limit : int = expo_backoff_limit
4951
5052 # connection states of kinesis client
5153 self .RECONNECT = "RECONNECT"
@@ -60,7 +62,7 @@ def __init__(
6062 self .create_stream = create_stream
6163 self .create_stream_shards = create_stream_shards
6264
63- async def __aenter__ (self ):
65+ async def __aenter__ (self ) -> "Base" :
6466
6567 log .info (
6668 "creating client with {}" .format (
@@ -78,12 +80,12 @@ async def __aenter__(self):
7880
7981 return self
8082
81- async def __aexit__ (self , exc_type , exc , tb ) :
83+ async def __aexit__ (self , exc_type : Any , exc : Any , tb : Any ) -> None :
8284 await self .close ()
8385 await self .client .__aexit__ (exc_type , exc , tb )
8486
8587 @property
86- def address (self ):
88+ def address (self ) -> Dict [ str , str ] :
8789 """
8890 Return address of stream, either as StreamName or StreamARN, when applicable.
8991
0 commit comments