Skip to content

Commit 779c363

Browse files
committed
Use functools.wraps instead of decorator
Signed-off-by: Yury Pliner <[email protected]>
1 parent 92b2397 commit 779c363

File tree

3 files changed

+26
-454
lines changed

3 files changed

+26
-454
lines changed

prometheus_client/context_managers.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1+
import functools
12
from timeit import default_timer
23
from types import TracebackType
34
from typing import (
45
Any, Callable, Literal, Optional, Tuple, Type, TYPE_CHECKING, TypeVar,
56
Union,
67
)
78

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

2827
def __call__(self, f: "F") -> "F":
29-
def wrapped(func, *args, **kwargs):
28+
@functools.wraps(f)
29+
def wrapped(*args: Any, **kwargs: Any) -> Any:
3030
with self:
31-
return func(*args, **kwargs)
32-
33-
return decorate(f, wrapped)
31+
return f(*args, **kwargs)
32+
return wrapped
3433

3534

3635
class InprogressTracker:
@@ -44,11 +43,11 @@ def __exit__(self, typ, value, traceback):
4443
self._gauge.dec()
4544

4645
def __call__(self, f: "F") -> "F":
47-
def wrapped(func, *args, **kwargs):
46+
@functools.wraps(f)
47+
def wrapped(*args: Any, **kwargs: Any) -> Any:
4848
with self:
49-
return func(*args, **kwargs)
50-
51-
return decorate(f, wrapped)
49+
return f(*args, **kwargs)
50+
return wrapped
5251

5352

5453
class Timer:
@@ -73,10 +72,10 @@ def labels(self, *args, **kw):
7372
self._metric = self._metric.labels(*args, **kw)
7473

7574
def __call__(self, f: "F") -> "F":
76-
def wrapped(func, *args, **kwargs):
75+
@functools.wraps(f)
76+
def wrapped(*args: Any, **kwargs: Any) -> Any:
7777
# Obtaining new instance of timer every time
7878
# ensures thread safety and reentrancy.
7979
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

Comments
 (0)