@@ -157,16 +157,41 @@ class Connection(typing.Generic[_Record], metaclass=ConnectionMeta):
157157 '_log_listeners' , '_termination_listeners' , '_cancellations' ,
158158 '_source_traceback' , '__weakref__' )
159159
160+ _protocol : '_cprotocol.BaseProtocol[_Record]'
161+ _transport : typing .Any
162+ _loop : asyncio .AbstractEventLoop
163+ _top_xact : typing .Optional [transaction .Transaction ]
164+ _aborted : bool
165+ _pool_release_ctr : int
166+ _stmt_cache : '_StatementCache'
167+ _stmts_to_close : typing .Set [
168+ '_cprotocol.PreparedStatementState[typing.Any]'
169+ ]
170+ _listeners : typing .Dict [str , typing .Set ['_Callback' ]]
171+ _server_version : types .ServerVersion
172+ _server_caps : 'ServerCapabilities'
173+ _intro_query : str
174+ _reset_query : typing .Optional [str ]
175+ _proxy : typing .Optional ['_pool.PoolConnectionProxy[typing.Any]' ]
176+ _stmt_exclusive_section : '_Atomic'
177+ _config : connect_utils ._ClientConfiguration
178+ _params : connect_utils ._ConnectionParameters
179+ _addr : typing .Union [typing .Tuple [str , int ], str ]
180+ _log_listeners : typing .Set ['_Callback' ]
181+ _termination_listeners : typing .Set ['_Callback' ]
182+ _cancellations : typing .Set ['asyncio.Task[typing.Any]' ]
183+ _source_traceback : typing .Optional [str ]
184+
160185 def __init__ (self , protocol : '_cprotocol.BaseProtocol[_Record]' ,
161186 transport : typing .Any ,
162187 loop : asyncio .AbstractEventLoop ,
163188 addr : typing .Union [typing .Tuple [str , int ], str ],
164189 config : connect_utils ._ClientConfiguration ,
165190 params : connect_utils ._ConnectionParameters ) -> None :
166- self ._protocol : '_cprotocol.BaseProtocol[_Record]' = protocol
191+ self ._protocol = protocol
167192 self ._transport = transport
168193 self ._loop = loop
169- self ._top_xact : typing . Optional [ transaction . Transaction ] = None
194+ self ._top_xact = None
170195 self ._aborted = False
171196 # Incremented every time the connection is released back to a pool.
172197 # Used to catch invalid references to connection-related resources
@@ -184,14 +209,12 @@ def __init__(self, protocol: '_cprotocol.BaseProtocol[_Record]',
184209 _weak_maybe_gc_stmt , weakref .ref (self )),
185210 max_lifetime = config .max_cached_statement_lifetime )
186211
187- self ._stmts_to_close : typing .Set [
188- '_cprotocol.PreparedStatementState[typing.Any]'
189- ] = set ()
212+ self ._stmts_to_close = set ()
190213
191- self ._listeners : typing . Dict [ str , typing . Set [ _Callback ]] = {}
192- self ._log_listeners : typing . Set [ _Callback ] = set ()
193- self ._cancellations : typing . Set [ asyncio . Task [ typing . Any ]] = set ()
194- self ._termination_listeners : typing . Set [ _Callback ] = set ()
214+ self ._listeners = {}
215+ self ._log_listeners = set ()
216+ self ._cancellations = set ()
217+ self ._termination_listeners = set ()
195218
196219 settings = self ._protocol .get_settings ()
197220 ver_string = settings .server_version
@@ -206,10 +229,8 @@ def __init__(self, protocol: '_cprotocol.BaseProtocol[_Record]',
206229 else :
207230 self ._intro_query = introspection .INTRO_LOOKUP_TYPES
208231
209- self ._reset_query : typing .Optional [str ] = None
210- self ._proxy : typing .Optional [
211- '_pool.PoolConnectionProxy[typing.Any]'
212- ] = None
232+ self ._reset_query = None
233+ self ._proxy = None
213234
214235 # Used to serialize operations that might involve anonymous
215236 # statements. Specifically, we want to make the following
@@ -221,7 +242,7 @@ def __init__(self, protocol: '_cprotocol.BaseProtocol[_Record]',
221242 self ._stmt_exclusive_section = _Atomic ()
222243
223244 if loop .get_debug ():
224- self ._source_traceback : typing . Optional [ str ] = _extract_stack ()
245+ self ._source_traceback = _extract_stack ()
225246 else :
226247 self ._source_traceback = None
227248
@@ -2007,7 +2028,7 @@ def _set_proxy(
20072028 self ._proxy = proxy
20082029
20092030 def _check_listeners (self ,
2010- listeners : ' typing.Sized' ,
2031+ listeners : typing .Sized ,
20112032 listener_type : str ) -> None :
20122033 if listeners :
20132034 count = len (listeners )
@@ -2927,6 +2948,11 @@ class _StatementCacheEntry(typing.Generic[_Record]):
29272948
29282949 __slots__ = ('_query' , '_statement' , '_cache' , '_cleanup_cb' )
29292950
2951+ _query : _StatementCacheKey [_Record ]
2952+ _statement : '_cprotocol.PreparedStatementState[_Record]'
2953+ _cache : '_StatementCache'
2954+ _cleanup_cb : typing .Optional [asyncio .TimerHandle ]
2955+
29302956 def __init__ (
29312957 self ,
29322958 cache : '_StatementCache' ,
@@ -2936,21 +2962,27 @@ def __init__(
29362962 self ._cache = cache
29372963 self ._query = query
29382964 self ._statement = statement
2939- self ._cleanup_cb : typing . Optional [ asyncio . TimerHandle ] = None
2965+ self ._cleanup_cb = None
29402966
29412967
29422968class _StatementCache :
29432969
29442970 __slots__ = ('_loop' , '_entries' , '_max_size' , '_on_remove' ,
29452971 '_max_lifetime' )
29462972
2973+ _loop : asyncio .AbstractEventLoop
2974+ _entries : 'collections.OrderedDict[_StatementCacheKey[typing.Any], _StatementCacheEntry[typing.Any]]' # noqa: E501
2975+ _max_size : int
2976+ _on_remove : OnRemove [typing .Any ]
2977+ _max_lifetime : float
2978+
29472979 def __init__ (self , * , loop : asyncio .AbstractEventLoop ,
29482980 max_size : int , on_remove : OnRemove [typing .Any ],
29492981 max_lifetime : float ) -> None :
2950- self ._loop : asyncio . AbstractEventLoop = loop
2951- self ._max_size : int = max_size
2952- self ._on_remove : OnRemove [ typing . Any ] = on_remove
2953- self ._max_lifetime : float = max_lifetime
2982+ self ._loop = loop
2983+ self ._max_size = max_size
2984+ self ._on_remove = on_remove
2985+ self ._max_lifetime = max_lifetime
29542986
29552987 # We use an OrderedDict for LRU implementation. Operations:
29562988 #
@@ -2969,10 +3001,7 @@ def __init__(self, *, loop: asyncio.AbstractEventLoop,
29693001 # So new entries and hits are always promoted to the end of the
29703002 # entries dict, whereas the unused one will group in the
29713003 # beginning of it.
2972- self ._entries : collections .OrderedDict [
2973- _StatementCacheKey [typing .Any ],
2974- _StatementCacheEntry [typing .Any ]
2975- ] = collections .OrderedDict ()
3004+ self ._entries = collections .OrderedDict ()
29763005
29773006 def __len__ (self ) -> int :
29783007 return len (self ._entries )
@@ -3148,6 +3177,8 @@ def from_callable(
31483177class _Atomic :
31493178 __slots__ = ('_acquired' ,)
31503179
3180+ _acquired : int
3181+
31513182 def __init__ (self ) -> None :
31523183 self ._acquired = 0
31533184
0 commit comments