@@ -157,16 +157,41 @@ class Connection(typing.Generic[_Record], metaclass=ConnectionMeta):
157
157
'_log_listeners' , '_termination_listeners' , '_cancellations' ,
158
158
'_source_traceback' , '__weakref__' )
159
159
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
+
160
185
def __init__ (self , protocol : '_cprotocol.BaseProtocol[_Record]' ,
161
186
transport : typing .Any ,
162
187
loop : asyncio .AbstractEventLoop ,
163
188
addr : typing .Union [typing .Tuple [str , int ], str ],
164
189
config : connect_utils ._ClientConfiguration ,
165
190
params : connect_utils ._ConnectionParameters ) -> None :
166
- self ._protocol : '_cprotocol.BaseProtocol[_Record]' = protocol
191
+ self ._protocol = protocol
167
192
self ._transport = transport
168
193
self ._loop = loop
169
- self ._top_xact : typing . Optional [ transaction . Transaction ] = None
194
+ self ._top_xact = None
170
195
self ._aborted = False
171
196
# Incremented every time the connection is released back to a pool.
172
197
# Used to catch invalid references to connection-related resources
@@ -184,14 +209,12 @@ def __init__(self, protocol: '_cprotocol.BaseProtocol[_Record]',
184
209
_weak_maybe_gc_stmt , weakref .ref (self )),
185
210
max_lifetime = config .max_cached_statement_lifetime )
186
211
187
- self ._stmts_to_close : typing .Set [
188
- '_cprotocol.PreparedStatementState[typing.Any]'
189
- ] = set ()
212
+ self ._stmts_to_close = set ()
190
213
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 ()
195
218
196
219
settings = self ._protocol .get_settings ()
197
220
ver_string = settings .server_version
@@ -206,10 +229,8 @@ def __init__(self, protocol: '_cprotocol.BaseProtocol[_Record]',
206
229
else :
207
230
self ._intro_query = introspection .INTRO_LOOKUP_TYPES
208
231
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
213
234
214
235
# Used to serialize operations that might involve anonymous
215
236
# statements. Specifically, we want to make the following
@@ -221,7 +242,7 @@ def __init__(self, protocol: '_cprotocol.BaseProtocol[_Record]',
221
242
self ._stmt_exclusive_section = _Atomic ()
222
243
223
244
if loop .get_debug ():
224
- self ._source_traceback : typing . Optional [ str ] = _extract_stack ()
245
+ self ._source_traceback = _extract_stack ()
225
246
else :
226
247
self ._source_traceback = None
227
248
@@ -2007,7 +2028,7 @@ def _set_proxy(
2007
2028
self ._proxy = proxy
2008
2029
2009
2030
def _check_listeners (self ,
2010
- listeners : ' typing.Sized' ,
2031
+ listeners : typing .Sized ,
2011
2032
listener_type : str ) -> None :
2012
2033
if listeners :
2013
2034
count = len (listeners )
@@ -2927,6 +2948,11 @@ class _StatementCacheEntry(typing.Generic[_Record]):
2927
2948
2928
2949
__slots__ = ('_query' , '_statement' , '_cache' , '_cleanup_cb' )
2929
2950
2951
+ _query : _StatementCacheKey [_Record ]
2952
+ _statement : '_cprotocol.PreparedStatementState[_Record]'
2953
+ _cache : '_StatementCache'
2954
+ _cleanup_cb : typing .Optional [asyncio .TimerHandle ]
2955
+
2930
2956
def __init__ (
2931
2957
self ,
2932
2958
cache : '_StatementCache' ,
@@ -2936,21 +2962,27 @@ def __init__(
2936
2962
self ._cache = cache
2937
2963
self ._query = query
2938
2964
self ._statement = statement
2939
- self ._cleanup_cb : typing . Optional [ asyncio . TimerHandle ] = None
2965
+ self ._cleanup_cb = None
2940
2966
2941
2967
2942
2968
class _StatementCache :
2943
2969
2944
2970
__slots__ = ('_loop' , '_entries' , '_max_size' , '_on_remove' ,
2945
2971
'_max_lifetime' )
2946
2972
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
+
2947
2979
def __init__ (self , * , loop : asyncio .AbstractEventLoop ,
2948
2980
max_size : int , on_remove : OnRemove [typing .Any ],
2949
2981
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
2954
2986
2955
2987
# We use an OrderedDict for LRU implementation. Operations:
2956
2988
#
@@ -2969,10 +3001,7 @@ def __init__(self, *, loop: asyncio.AbstractEventLoop,
2969
3001
# So new entries and hits are always promoted to the end of the
2970
3002
# entries dict, whereas the unused one will group in the
2971
3003
# beginning of it.
2972
- self ._entries : collections .OrderedDict [
2973
- _StatementCacheKey [typing .Any ],
2974
- _StatementCacheEntry [typing .Any ]
2975
- ] = collections .OrderedDict ()
3004
+ self ._entries = collections .OrderedDict ()
2976
3005
2977
3006
def __len__ (self ) -> int :
2978
3007
return len (self ._entries )
@@ -3148,6 +3177,8 @@ def from_callable(
3148
3177
class _Atomic :
3149
3178
__slots__ = ('_acquired' ,)
3150
3179
3180
+ _acquired : int
3181
+
3151
3182
def __init__ (self ) -> None :
3152
3183
self ._acquired = 0
3153
3184
0 commit comments