Skip to content

Commit 1c08a7b

Browse files
committed
connection: Tighten up the code
1 parent c6179cc commit 1c08a7b

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

asyncpg/connection.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,8 @@ async def execute(self, query: str, *args, timeout: float=None) -> str:
141141
return await self._protocol.query(query, timeout)
142142

143143
stmt = await self._get_statement(query, timeout)
144-
protocol = self._protocol
145-
_, status, _ = await protocol.bind_execute(stmt, args, '', 0,
146-
True, timeout)
144+
_, status, _ = await self._protocol.bind_execute(stmt, args, '', 0,
145+
True, timeout)
147146
return status.decode()
148147

149148
async def _get_statement(self, query, timeout):
@@ -218,8 +217,8 @@ async def fetch(self, query, *args, timeout=None) -> list:
218217
:return list: A list of :class:`Record` instances.
219218
"""
220219
stmt = await self._get_statement(query, timeout)
221-
protocol = self._protocol
222-
data = await protocol.bind_execute(stmt, args, '', 0, False, timeout)
220+
data = await self._protocol.bind_execute(stmt, args, '', 0,
221+
False, timeout)
223222
return data
224223

225224
async def fetchval(self, query, *args, column=0, timeout=None):
@@ -237,8 +236,8 @@ async def fetchval(self, query, *args, column=0, timeout=None):
237236
:return: The value of the specified column of the first record.
238237
"""
239238
stmt = await self._get_statement(query, timeout)
240-
protocol = self._protocol
241-
data = await protocol.bind_execute(stmt, args, '', 1, False, timeout)
239+
data = await self._protocol.bind_execute(stmt, args, '', 1,
240+
False, timeout)
242241
if not data:
243242
return None
244243
return data[0][column]
@@ -253,8 +252,8 @@ async def fetchrow(self, query, *args, timeout=None):
253252
:return: The first row as a :class:`Record` instance.
254253
"""
255254
stmt = await self._get_statement(query, timeout)
256-
protocol = self._protocol
257-
data = await protocol.bind_execute(stmt, args, '', 1, False, timeout)
255+
data = await self._protocol.bind_execute(stmt, args, '', 1,
256+
False, timeout)
258257
if not data:
259258
return None
260259
return data[0]
@@ -335,8 +334,7 @@ async def close(self):
335334
self._close_stmts()
336335
self._listeners = {}
337336
self._aborted = True
338-
protocol = self._protocol
339-
await protocol.close()
337+
await self._protocol.close()
340338

341339
def terminate(self):
342340
"""Terminate the connection without waiting for pending data."""
@@ -377,9 +375,8 @@ def _maybe_gc_stmt(self, stmt):
377375
async def _cleanup_stmts(self):
378376
to_close = self._stmts_to_close
379377
self._stmts_to_close = set()
380-
protocol = self._protocol
381378
for stmt in to_close:
382-
await protocol.close_statement(stmt, False)
379+
await self._protocol.close_statement(stmt, False)
383380

384381
def _request_portal_name(self):
385382
return self._get_unique_id()

0 commit comments

Comments
 (0)