Created
June 25, 2024 15:19
-
-
Save jacek-jablonski/5b23d34e42030ab68cfa4e5576c016a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections.abc import Callable, Collection | |
from typing import ParamSpec, TypeVar | |
R = TypeVar("R") | |
P = ParamSpec("P") | |
def disable( | |
func_or_metrics: Collection[int] | Callable[P, R] | |
) -> Callable[[Callable[P, R]], Callable[P, R]] | Callable[P, R]: | |
def _disable(f: Callable[P, R], metrics: Collection[int]) -> None: | |
if metrics: | |
print(metrics) | |
if callable(func_or_metrics): | |
_disable(func_or_metrics, []) | |
return func_or_metrics | |
else: | |
def wrapper(f: Callable[P, R]) -> Callable[P, R]: | |
_disable(f, func_or_metrics) | |
return f | |
return wrapper | |
@disable | |
def _test_endpoint1() -> str: | |
return "Hello" | |
@disable([1]) | |
def _test_endpoint2() -> str: | |
return "Hello" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment