11import re
22import typing as t
3+ from collections .abc import Awaitable , Mapping , Sequence
34
45import psqlpy
56import wrapt # type: ignore[import-untyped]
@@ -76,7 +77,7 @@ def _construct_span(
7677 if hosts :
7778 span_attributes [SpanAttributes .SERVER_ADDRESS ] = ", " .join (hosts )
7879 span_attributes [SpanAttributes .SERVER_PORT ] = ", " .join (
79- [str (port ) for port in ports ]
80+ [str (port ) for port in ports ],
8081 )
8182 span_attributes [SpanAttributes .NETWORK_TRANSPORT ] = (
8283 NetTransportValues .IP_TCP .value
@@ -85,7 +86,7 @@ def _construct_span(
8586 elif host_addrs :
8687 span_attributes [SpanAttributes .SERVER_ADDRESS ] = ", " .join (host_addrs )
8788 span_attributes [SpanAttributes .SERVER_PORT ] = ", " .join (
88- [str (port ) for port in ports ]
89+ [str (port ) for port in ports ],
8990 )
9091 span_attributes [SpanAttributes .NETWORK_TRANSPORT ] = (
9192 NetTransportValues .IP_TCP .value
@@ -171,7 +172,13 @@ def _uninstrument(self, **__: t.Any) -> None:
171172 for method_name in methods :
172173 unwrap (cls , method_name )
173174
174- async def _do_execute (self , func , instance , args , kwargs ):
175+ async def _do_execute (
176+ self ,
177+ func : t .Callable [..., Awaitable [t .Any ]],
178+ instance : t .Union [psqlpy .Connection , psqlpy .Transaction , psqlpy .Cursor ],
179+ args : Sequence [t .Any ],
180+ kwargs : Mapping [str , t .Any ],
181+ ) -> t .Any :
175182 exception = None
176183 params = getattr (instance , "_params" , {})
177184 name = args [0 ] if args else params .get ("database" , "postgresql" )
@@ -182,20 +189,20 @@ async def _do_execute(self, func, instance, args, kwargs):
182189 except IndexError :
183190 name = ""
184191
185- with self ._tracer .start_as_current_span (
192+ with self ._tracer .start_as_current_span ( # type: ignore[union-attr]
186193 name ,
187194 kind = SpanKind .CLIENT ,
188195 ) as span :
189196 if span .is_recording ():
190197 span_attributes = _construct_span (
191198 instance ,
192- _retrieve_parameter_from_args_or_kwargs (
199+ _retrieve_parameter_from_args_or_kwargs ( # type: ignore[arg-type]
193200 parameter_name = "querystring" ,
194201 parameter_index = 0 ,
195202 args = args ,
196203 kwargs = kwargs ,
197204 ),
198- _retrieve_parameter_from_args_or_kwargs (
205+ _retrieve_parameter_from_args_or_kwargs ( # type: ignore[arg-type]
199206 parameter_name = "parameters" ,
200207 parameter_index = 1 ,
201208 args = args ,
@@ -222,13 +229,19 @@ async def _do_execute(self, func, instance, args, kwargs):
222229
223230 return result
224231
225- async def _do_cursor_execute (self , func , instance , args , kwargs ):
232+ async def _do_cursor_execute (
233+ self ,
234+ func : t .Callable [..., Awaitable [t .Any ]],
235+ instance : psqlpy .Cursor ,
236+ args : Sequence [t .Any ],
237+ kwargs : Mapping [str , t .Any ],
238+ ) -> t .Any :
226239 """Wrap cursor based functions. For every call this will generate a new span."""
227240 exception = None
228241
229242 stop = False
230- with self ._tracer .start_as_current_span (
231- f "CURSOR" ,
243+ with self ._tracer .start_as_current_span ( # type: ignore[union-attr]
244+ "CURSOR" ,
232245 kind = SpanKind .CLIENT ,
233246 ) as span :
234247 if span .is_recording ():
0 commit comments