171171import functools
172172import logging
173173import re
174- from typing import Any , Awaitable , Callable , Generic , TypeVar
174+ from typing import Any , Awaitable , Callable , Generic , Literal , TypeVar
175175
176176from wrapt import wrap_function_wrapper
177177
210210 "MySQLdb" : "mysqlclient" ,
211211}
212212
213+ CommentPositionT = Literal ["start" , "end" ]
214+
213215_logger = logging .getLogger (__name__ )
214216
215217ConnectionT = TypeVar ("ConnectionT" )
216218CursorT = TypeVar ("CursorT" )
217219
218220
219- def trace_integration (
221+ def trace_integration ( # pylint: disable=too-many-positional-arguments
220222 connect_module : Callable [..., Any ],
221223 connect_method_name : str ,
222224 database_system : str ,
@@ -227,7 +229,7 @@ def trace_integration(
227229 db_api_integration_factory : type [DatabaseApiIntegration ] | None = None ,
228230 enable_attribute_commenter : bool = False ,
229231 commenter_options : dict [str , Any ] | None = None ,
230- comment_position : str = "end" ,
232+ comment_position : CommentPositionT = "end" ,
231233):
232234 """Integrate with DB API library.
233235 https://www.python.org/dev/peps/pep-0249/
@@ -265,7 +267,7 @@ def trace_integration(
265267 )
266268
267269
268- def wrap_connect (
270+ def wrap_connect ( # pylint: disable=too-many-positional-arguments
269271 name : str ,
270272 connect_module : Callable [..., Any ],
271273 connect_method_name : str ,
@@ -278,7 +280,7 @@ def wrap_connect(
278280 db_api_integration_factory : type [DatabaseApiIntegration ] | None = None ,
279281 commenter_options : dict [str , Any ] | None = None ,
280282 enable_attribute_commenter : bool = False ,
281- comment_position : str = "end" ,
283+ comment_position : CommentPositionT = "end" ,
282284):
283285 """Integrate with DB API library.
284286 https://www.python.org/dev/peps/pep-0249/
@@ -347,7 +349,7 @@ def unwrap_connect(
347349 unwrap (connect_module , connect_method_name )
348350
349351
350- def instrument_connection (
352+ def instrument_connection ( # pylint: disable=too-many-positional-arguments
351353 name : str ,
352354 connection : ConnectionT | TracedConnectionProxy [ConnectionT ],
353355 database_system : str ,
@@ -360,7 +362,7 @@ def instrument_connection(
360362 connect_module : Callable [..., Any ] | None = None ,
361363 enable_attribute_commenter : bool = False ,
362364 db_api_integration_factory : type [DatabaseApiIntegration ] | None = None ,
363- comment_position : str = "end" ,
365+ comment_position : CommentPositionT = "end" ,
364366) -> TracedConnectionProxy [ConnectionT ]:
365367 """Enable instrumentation in a database connection.
366368
@@ -430,7 +432,7 @@ def uninstrument_connection(
430432
431433
432434class DatabaseApiIntegration :
433- def __init__ (
435+ def __init__ ( # pylint: disable=too-many-positional-arguments
434436 self ,
435437 name : str ,
436438 database_system : str ,
@@ -442,7 +444,7 @@ def __init__(
442444 commenter_options : dict [str , Any ] | None = None ,
443445 connect_module : Callable [..., Any ] | None = None ,
444446 enable_attribute_commenter : bool = False ,
445- comment_position : str = "end" ,
447+ comment_position : CommentPositionT = "end" ,
446448 ):
447449 if connection_attributes is None :
448450 self .connection_attributes = {
@@ -689,7 +691,11 @@ def _update_args_with_added_sql_comment(self, args, cursor) -> tuple:
689691 args_list [0 ] = args_list [0 ].as_string (cursor .connection )
690692
691693 args_list [0 ] = str (args_list [0 ])
692- statement = _add_sql_comment (args_list [0 ], comment_position = self ._db_api_integration .comment_position , ** commenter_data )
694+ statement = _add_sql_comment (
695+ args_list [0 ],
696+ comment_position = self ._db_api_integration .comment_position ,
697+ ** commenter_data ,
698+ )
693699 args_list [0 ] = statement
694700 args = tuple (args_list )
695701 except Exception as exc : # pylint: disable=broad-except
0 commit comments