Skip to content

TYP: privatize type alias in pandas/util/_decorators.py #29882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions pandas/util/_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

from pandas._libs.properties import cache_readonly # noqa

FuncType = Callable[..., Any]
F = TypeVar("F", bound=FuncType)
_FuncType = Callable[..., Any]
_F = TypeVar("_F", bound=_FuncType)


def deprecate(
Expand Down Expand Up @@ -106,7 +106,7 @@ def deprecate_kwarg(
new_arg_name: Optional[str],
mapping: Optional[Union[Mapping[Any, Any], Callable[[Any], Any]]] = None,
stacklevel: int = 2,
) -> Callable[..., Any]:
) -> Callable[[_F], _F]:
"""
Decorator to deprecate a keyword argument of a function.

Expand Down Expand Up @@ -174,7 +174,7 @@ def deprecate_kwarg(
"mapping from old to new argument values must be dict or callable!"
)

def _deprecate_kwarg(func: F) -> F:
def _deprecate_kwarg(func: _F) -> _F:
@wraps(func)
def wrapper(*args, **kwargs) -> Callable[..., Any]:
old_arg_value = kwargs.pop(old_arg_name, None)
Expand Down Expand Up @@ -221,15 +221,15 @@ def wrapper(*args, **kwargs) -> Callable[..., Any]:
kwargs[new_arg_name] = new_arg_value
return func(*args, **kwargs)

return cast(F, wrapper)
return cast(_F, wrapper)

return _deprecate_kwarg


def rewrite_axis_style_signature(
name: str, extra_params: List[Tuple[str, Any]]
) -> Callable[..., Any]:
def decorate(func: F) -> F:
def decorate(func: _F) -> _F:
@wraps(func)
def wrapper(*args, **kwargs) -> Callable[..., Any]:
return func(*args, **kwargs)
Expand All @@ -250,7 +250,7 @@ def wrapper(*args, **kwargs) -> Callable[..., Any]:

# https://github.com/python/typing/issues/598
func.__signature__ = sig # type: ignore
return cast(F, wrapper)
return cast(_F, wrapper)

return decorate

Expand Down Expand Up @@ -294,7 +294,7 @@ def __init__(self, *args, **kwargs):

self.params = args or kwargs

def __call__(self, func: F) -> F:
def __call__(self, func: _F) -> _F:
func.__doc__ = func.__doc__ and func.__doc__ % self.params
return func

Expand Down Expand Up @@ -336,7 +336,7 @@ def __init__(self, addendum: Optional[str], join: str = "", indents: int = 0):
self.addendum = addendum
self.join = join

def __call__(self, func: F) -> F:
def __call__(self, func: _F) -> _F:
func.__doc__ = func.__doc__ if func.__doc__ else ""
self.addendum = self.addendum if self.addendum else ""
docitems = [func.__doc__, self.addendum]
Expand Down