Skip to content

Commit

Permalink
FIX-modin-project#7278: Make sure 'enable_logging' decorator preserve…
Browse files Browse the repository at this point in the history
… type hints

Signed-off-by: Anatoly Myachev <anatoly.myachev@intel.com>
  • Loading branch information
anmyachev committed May 16, 2024
1 parent 685f7ba commit 2d07e88
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions modin/logging/logger_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@

from functools import wraps
from types import FunctionType, MethodType
from typing import Any, Callable, Dict, Optional, Tuple, Type, Union
from typing import Any, Callable, Dict, Optional, Tuple, Type, TypeVar, Union, overload

from modin.config import LogMode

from .config import LogLevel, get_logger

_MODIN_LOGGER_NOWRAP = "__modin_logging_nowrap__"

Fn = TypeVar("Fn", bound=Callable)


def disable_logging(func: Callable) -> Callable:
"""
Expand All @@ -46,11 +48,17 @@ def disable_logging(func: Callable) -> Callable:
return func


@overload
def enable_logging(modin_layer: Fn) -> Fn:
# This helps preserve typings when the decorator is used without parentheses
...


def enable_logging(
modin_layer: Union[str, Callable, Type] = "PANDAS-API",
modin_layer: Union[str, Fn, Type] = "PANDAS-API",
name: Optional[str] = None,
log_level: LogLevel = LogLevel.INFO,
) -> Callable:
) -> Callable[[Fn], Fn]:
"""
Log Decorator used on specific Modin functions or classes.
Expand All @@ -76,7 +84,7 @@ def enable_logging(
# def func()
return enable_logging()(modin_layer)

def decorator(obj: Any) -> Any:
def decorator(obj: Fn) -> Fn:
"""Decorate function or class to add logs to Modin API function(s)."""
if isinstance(obj, type):
seen: Dict[Any, Any] = {}
Expand Down

0 comments on commit 2d07e88

Please sign in to comment.