Skip to content

Commit bb326fc

Browse files
committed
Make timeout param of executemany a keyword-only kwarg.
This commit removes a compatibility layer from the `executemany()` function allowing to pass `timeout` as a positional argument.
1 parent 682c066 commit bb326fc

File tree

2 files changed

+1
-68
lines changed

2 files changed

+1
-68
lines changed

asyncpg/connection.py

+1-42
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,7 @@ async def execute(self, query: str, *args, timeout: float=None) -> str:
218218
_, status, _ = await self._execute(query, args, 0, timeout, True)
219219
return status.decode()
220220

221-
async def executemany(self, command: str, args,
222-
_timeout: float=None, **kw):
223-
# The real signature of this method is:
224-
#
225-
# executemany(self, command: str, args, *, timeout: float=None)
226-
#
221+
async def executemany(self, command: str, args, *, timeout: float=None):
227222
"""Execute an SQL *command* for each sequence of arguments in *args*.
228223
229224
Example:
@@ -242,24 +237,6 @@ async def executemany(self, command: str, args,
242237
.. versionadded:: 0.7.0
243238
"""
244239
self._check_open()
245-
246-
if 'timeout' in kw:
247-
timeout = kw.pop('timeout')
248-
else:
249-
timeout = _timeout
250-
if timeout is not None:
251-
warnings.warn(
252-
"Passing 'timeout' as a positional argument to "
253-
"executemany() is deprecated and will be removed in "
254-
"asyncpg 0.11.0. Pass it as a keyword argument instead: "
255-
"`executemany(..., timeout=...)`.",
256-
DeprecationWarning, stacklevel=2)
257-
if kw:
258-
first_kwarg = next(iter(kw))
259-
raise TypeError(
260-
'executemany() got an unexpected keyword argument {!r}'.format(
261-
first_kwarg))
262-
263240
return await self._executemany(command, args, timeout)
264241

265242
async def _get_statement(self, query, timeout, *, named: bool=False):
@@ -1290,21 +1267,3 @@ def _detect_server_capabilities(server_version, connection_settings):
12901267
sql_reset=sql_reset,
12911268
sql_close_all=sql_close_all
12921269
)
1293-
1294-
1295-
def _patch_executemany_signature():
1296-
# Patch Connection.executemany() signature to remove '**kw' parameter
1297-
# and change '_timeout' keyword arg to 'timeout' keyword-only arg.
1298-
# TODO Remove in 0.11.0.
1299-
import inspect
1300-
sig = inspect.signature(Connection.executemany)
1301-
params = sig.parameters.copy()
1302-
params.pop('kw')
1303-
timeout = params.pop('_timeout')
1304-
timeout = timeout.replace(name='timeout', kind=timeout.KEYWORD_ONLY)
1305-
params['timeout'] = timeout
1306-
Connection.executemany.__signature__ = sig.replace(
1307-
parameters=params.values())
1308-
1309-
1310-
_patch_executemany_signature()

tests/test_execute.py

-26
Original file line numberDiff line numberDiff line change
@@ -154,29 +154,3 @@ async def test_execute_many_2(self):
154154
''', good_data)
155155
finally:
156156
await self.con.execute('DROP TABLE exmany')
157-
158-
async def test_execute_many_3_kwonly_timeout(self):
159-
with self.assertWarnsRegex(DeprecationWarning,
160-
"Passing 'timeout' as a positional"):
161-
await self.con.executemany(
162-
'''SELECT $1::int''',
163-
[(1,), (2,)],
164-
1)
165-
166-
with warnings.catch_warnings():
167-
warnings.simplefilter("error")
168-
169-
# Test that passing timeout as a kwarg doesn't trigger a warning.
170-
await self.con.executemany(
171-
'''SELECT $1::int''',
172-
[(1,), (2,)],
173-
timeout=1)
174-
175-
# Test that not passing timeout is fine too.
176-
await self.con.executemany(
177-
'''SELECT $1::int''',
178-
[(1,), (2,)])
179-
180-
self.assertEqual(
181-
str(inspect.signature(self.con.executemany)),
182-
'(command:str, args, *, timeout:float=None)')

0 commit comments

Comments
 (0)