1313import struct
1414import time
1515import urllib .parse
16+ import warnings
1617
1718from . import cursor
1819from . import exceptions
@@ -216,7 +217,12 @@ async def execute(self, query: str, *args, timeout: float=None) -> str:
216217 _ , status , _ = await self ._execute (query , args , 0 , timeout , True )
217218 return status .decode ()
218219
219- async def executemany (self , command : str , args , timeout : float = None ):
220+ async def executemany (self , command : str , args ,
221+ _timeout : float = None , ** kw ):
222+ # The real signature of this method is:
223+ #
224+ # executemany(self, command: str, args, *, timeout: float=None)
225+ #
220226 """Execute an SQL *command* for each sequence of arguments in *args*.
221227
222228 Example:
@@ -234,6 +240,23 @@ async def executemany(self, command: str, args, timeout: float=None):
234240
235241 .. versionadded:: 0.7.0
236242 """
243+ if 'timeout' in kw :
244+ timeout = kw .pop ('timeout' )
245+ else :
246+ timeout = _timeout
247+ if timeout is not None :
248+ warnings .warn (
249+ "Passing 'timeout' as a positional argument to "
250+ "executemany() is deprecated and will be removed in "
251+ "asyncpg 0.11.0. Pass it as a keyword argument instead: "
252+ "`executemany(..., timeout=...)`." ,
253+ DeprecationWarning , stacklevel = 2 )
254+ if kw :
255+ first_kwarg = next (iter (kw ))
256+ raise TypeError (
257+ 'executemany() got an unexpected keyword argument {!r}' .format (
258+ first_kwarg ))
259+
237260 return await self ._executemany (command , args , timeout )
238261
239262 async def _get_statement (self , query , timeout , * , named : bool = False ):
@@ -948,3 +971,21 @@ def _detect_server_capabilities(server_version, connection_settings):
948971 sql_reset = sql_reset ,
949972 sql_close_all = sql_close_all
950973 )
974+
975+
976+ def _patch_executemany_signature ():
977+ # Patch Connection.executemany() signature to remove '**kw' parameter
978+ # and change '_timeout' keyword arg to 'timeout' keyword-only arg.
979+ # TODO Remove in 0.11.0.
980+ import inspect
981+ sig = inspect .signature (Connection .executemany )
982+ params = sig .parameters .copy ()
983+ params .pop ('kw' )
984+ timeout = params .pop ('_timeout' )
985+ timeout = timeout .replace (name = 'timeout' , kind = timeout .KEYWORD_ONLY )
986+ params ['timeout' ] = timeout
987+ Connection .executemany .__signature__ = sig .replace (
988+ parameters = params .values ())
989+
990+
991+ _patch_executemany_signature ()
0 commit comments