Skip to content

Commit 0ab483c

Browse files
committed
Use functools.wraps instead of decorator
Signed-off-by: Yury Pliner <[email protected]>
1 parent ecb5dd9 commit 0ab483c

File tree

3 files changed

+24
-454
lines changed

3 files changed

+24
-454
lines changed

prometheus_client/context_managers.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import functools
12
import sys
23
from timeit import default_timer
34
from types import TracebackType
@@ -6,8 +7,6 @@
67
if sys.version_info >= (3, 8, 0):
78
from typing import Literal
89

9-
from .decorator import decorate
10-
1110
if TYPE_CHECKING:
1211
from . import Counter
1312
F = TypeVar("F", bound=Callable[..., Any])
@@ -27,11 +26,11 @@ def __exit__(self, typ: Optional[Type[BaseException]], value: Optional[BaseExcep
2726
return False
2827

2928
def __call__(self, f: "F") -> "F":
30-
def wrapped(func, *args, **kwargs):
29+
@functools.wraps(f)
30+
def wrapped(*args: Any, **kwargs: Any) -> Any:
3131
with self:
32-
return func(*args, **kwargs)
33-
34-
return decorate(f, wrapped)
32+
return f(*args, **kwargs)
33+
return wrapped
3534

3635

3736
class InprogressTracker:
@@ -45,11 +44,11 @@ def __exit__(self, typ, value, traceback):
4544
self._gauge.dec()
4645

4746
def __call__(self, f):
48-
def wrapped(func, *args, **kwargs):
47+
@functools.wraps(f)
48+
def wrapped(*args: Any, **kwargs: Any) -> Any:
4949
with self:
50-
return func(*args, **kwargs)
51-
52-
return decorate(f, wrapped)
50+
return f(*args, **kwargs)
51+
return wrapped
5352

5453

5554
class Timer:
@@ -74,10 +73,8 @@ def labels(self, *args, **kw):
7473
self._metric = self._metric.labels(*args, **kw)
7574

7675
def __call__(self, f):
77-
def wrapped(func, *args, **kwargs):
78-
# Obtaining new instance of timer every time
79-
# ensures thread safety and reentrancy.
76+
@functools.wraps(f)
77+
def wrapped(*args: Any, **kwargs: Any) -> Any:
8078
with self._new_timer():
81-
return func(*args, **kwargs)
82-
83-
return decorate(f, wrapped)
79+
return f(*args, **kwargs)
80+
return wrapped

0 commit comments

Comments
 (0)