1
+ import functools
1
2
from timeit import default_timer
2
3
from types import TracebackType
3
4
from typing import (
4
5
Any , Callable , Literal , Optional , Tuple , Type , TYPE_CHECKING , TypeVar ,
5
6
Union ,
6
7
)
7
8
8
- from .decorator import decorate
9
-
10
9
if TYPE_CHECKING :
11
10
from . import Counter
12
11
F = TypeVar ("F" , bound = Callable [..., Any ])
@@ -26,11 +25,11 @@ def __exit__(self, typ: Optional[Type[BaseException]], value: Optional[BaseExcep
26
25
return False
27
26
28
27
def __call__ (self , f : "F" ) -> "F" :
29
- def wrapped (func , * args , ** kwargs ):
28
+ @functools .wraps (f )
29
+ def wrapped (* args : Any , ** kwargs : Any ) -> Any :
30
30
with self :
31
- return func (* args , ** kwargs )
32
-
33
- return decorate (f , wrapped )
31
+ return f (* args , ** kwargs )
32
+ return wrapped
34
33
35
34
36
35
class InprogressTracker :
@@ -44,11 +43,11 @@ def __exit__(self, typ, value, traceback):
44
43
self ._gauge .dec ()
45
44
46
45
def __call__ (self , f : "F" ) -> "F" :
47
- def wrapped (func , * args , ** kwargs ):
46
+ @functools .wraps (f )
47
+ def wrapped (* args : Any , ** kwargs : Any ) -> Any :
48
48
with self :
49
- return func (* args , ** kwargs )
50
-
51
- return decorate (f , wrapped )
49
+ return f (* args , ** kwargs )
50
+ return wrapped
52
51
53
52
54
53
class Timer :
@@ -73,10 +72,10 @@ def labels(self, *args, **kw):
73
72
self ._metric = self ._metric .labels (* args , ** kw )
74
73
75
74
def __call__ (self , f : "F" ) -> "F" :
76
- def wrapped (func , * args , ** kwargs ):
75
+ @functools .wraps (f )
76
+ def wrapped (* args : Any , ** kwargs : Any ) -> Any :
77
77
# Obtaining new instance of timer every time
78
78
# ensures thread safety and reentrancy.
79
79
with self ._new_timer ():
80
- return func (* args , ** kwargs )
81
-
82
- return decorate (f , wrapped )
80
+ return f (* args , ** kwargs )
81
+ return wrapped
0 commit comments