Skip to content
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
17 changes: 8 additions & 9 deletions python/pyspark/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,18 @@
from pyspark.version import __version__
from pyspark._globals import _NoValue # noqa: F401

T = TypeVar("T")
F = TypeVar("F", bound=Callable)
_F = TypeVar("_F", bound=Callable)


def since(version: Union[str, float]) -> Callable[[F], F]:
def since(version: Union[str, float]) -> Callable[[_F], _F]:
"""
A decorator that annotates a function to append the version of Spark the function was added.
"""
import re

indent_p = re.compile(r"\n( +)")

def deco(f: F) -> F:
def deco(f: _F) -> _F:
assert f.__doc__ is not None

indents = indent_p.findall(f.__doc__)
Expand All @@ -93,11 +92,11 @@ def deco(f: F) -> F:


def copy_func(
f: F,
f: _F,
name: Optional[str] = None,
sinceversion: Optional[Union[str, float]] = None,
doc: Optional[str] = None,
) -> F:
) -> _F:
"""
Returns a function with same code, globals, defaults, closure, and
name (or provide a new name).
Expand All @@ -119,10 +118,10 @@ def copy_func(
fn.__doc__ = doc
if sinceversion is not None:
fn = since(sinceversion)(fn)
return cast(F, fn)
return cast(_F, fn)


def keyword_only(func: F) -> F:
def keyword_only(func: _F) -> _F:
"""
A decorator that forces keyword arguments in the wrapped method
and saves actual input keyword arguments in `_input_kwargs`.
Expand All @@ -139,7 +138,7 @@ def wrapper(self: Any, *args: Any, **kwargs: Any) -> Any:
self._input_kwargs = kwargs
return func(self, **kwargs)

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


# To avoid circular dependencies
Expand Down