Skip to content

TYP: annotate two decorators #47184

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

Merged
merged 1 commit into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion pandas/core/computation/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
)
from typing import (
TYPE_CHECKING,
Callable,
Sequence,
)
import warnings
Expand All @@ -28,6 +29,8 @@
from pandas.core.computation.common import result_type_many

if TYPE_CHECKING:
from pandas._typing import F

from pandas.core.generic import NDFrame
from pandas.core.indexes.api import Index

Expand Down Expand Up @@ -62,7 +65,7 @@ def _any_pandas_objects(terms) -> bool:
return any(isinstance(term.value, PandasObject) for term in terms)


def _filter_special_cases(f):
def _filter_special_cases(f) -> Callable[[F], F]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is only used once to decorate the defined function below, so maybe can follow up by combining the two functions

@wraps(f)
def wrapper(terms):
# single unary operand
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ def _groupby_and_merge(by, left: DataFrame, right: DataFrame, merge_pieces):
lcols = lhs.columns.tolist()
cols = lcols + [r for r in right.columns if r not in set(lcols)]
merged = lhs.reindex(columns=cols)
merged.index = range(len(merged))
# error: Incompatible types in assignment (expression has type
# "range", variable has type "Index")
merged.index = range(len(merged)) # type: ignore[assignment]
pieces.append(merged)
continue

Expand Down
2 changes: 1 addition & 1 deletion pandas/util/_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def wrapper(*args, **kwargs):

def rewrite_axis_style_signature(
name: str, extra_params: list[tuple[str, Any]]
) -> Callable[..., Any]:
) -> Callable[[F], F]:
def decorate(func: F) -> F:
@wraps(func)
def wrapper(*args, **kwargs) -> Callable[..., Any]:
Expand Down