Skip to content

Commit

Permalink
cleanup callable type hint with typevar
Browse files Browse the repository at this point in the history
  • Loading branch information
quentin-quix committed Dec 19, 2024
1 parent 5457b54 commit 965939d
Showing 1 changed file with 6 additions and 24 deletions.
30 changes: 6 additions & 24 deletions quixstreams/dataframe/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
Literal,
Optional,
Tuple,
TypeVar,
Union,
cast,
overload,
Expand Down Expand Up @@ -1324,31 +1325,12 @@ def _drop(value: Dict, columns: List[str], ignore_missing: bool = False):
raise


@overload
def _as_metadata_func(
func: ApplyCallbackStateful,
) -> ApplyWithMetadataCallbackStateful: ...


@overload
def _as_metadata_func(
func: FilterCallbackStateful,
) -> FilterWithMetadataCallbackStateful: ...


@overload
def _as_metadata_func(
func: UpdateCallbackStateful,
) -> UpdateWithMetadataCallbackStateful: ...
T = TypeVar("T")


def _as_metadata_func(
func: Union[ApplyCallbackStateful, FilterCallbackStateful, UpdateCallbackStateful],
) -> Union[
ApplyWithMetadataCallbackStateful,
FilterWithMetadataCallbackStateful,
UpdateWithMetadataCallbackStateful,
]:
func: Callable[[Any, State], T],
) -> Callable[[Any, Any, int, Any, State], T]:
@functools.wraps(func)
def wrapper(
value: Any, _key: Any, _timestamp: int, _headers: Any, state: State
Expand All @@ -1359,9 +1341,9 @@ def wrapper(


def _as_stateful(
func: ApplyWithMetadataCallbackStateful,
func: Callable[[Any, Any, int, Any, State], T],
processing_context: ProcessingContext,
) -> ApplyWithMetadataCallback:
) -> Callable[[Any, Any, int, Any], T]:
@functools.wraps(func)
def wrapper(value: Any, key: Any, timestamp: int, headers: Any) -> Any:
ctx = message_context()
Expand Down

0 comments on commit 965939d

Please sign in to comment.