Skip to content

Commit 7201454

Browse files
committed
chore(typing): resolve mypy strict errors
Following #2077
1 parent 0d6d2fc commit 7201454

File tree

6 files changed

+16
-11
lines changed

6 files changed

+16
-11
lines changed

narwhals/_arrow/dataframe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ def collect(
618618
self: Self,
619619
backend: Implementation | None,
620620
**kwargs: Any,
621-
) -> CompliantDataFrame:
621+
) -> CompliantDataFrame[Any]:
622622
if backend is Implementation.PYARROW or backend is None:
623623
from narwhals._arrow.dataframe import ArrowDataFrame
624624

narwhals/_expression_parsing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def maybe_evaluate_expr(
9090

9191

9292
@overload
93-
def maybe_evaluate_expr(df: CompliantDataFrame, expr: T) -> T: ...
93+
def maybe_evaluate_expr(df: CompliantDataFrame[Any], expr: T) -> T: ...
9494

9595

9696
def maybe_evaluate_expr(
@@ -152,7 +152,7 @@ def reuse_series_implementation(
152152
"""
153153
plx = expr.__narwhals_namespace__()
154154

155-
def func(df: CompliantDataFrame) -> Sequence[CompliantSeries]:
155+
def func(df: CompliantDataFrame[Any]) -> Sequence[CompliantSeries]:
156156
_kwargs = {
157157
**(call_kwargs or {}),
158158
**{
@@ -303,7 +303,7 @@ def extract_compliant(
303303

304304
def evaluate_output_names_and_aliases(
305305
expr: CompliantExpr[Any, Any],
306-
df: CompliantDataFrame | CompliantLazyFrame,
306+
df: CompliantDataFrame[Any] | CompliantLazyFrame,
307307
exclude: Sequence[str],
308308
) -> tuple[Sequence[str], Sequence[str]]:
309309
output_names = expr._evaluate_output_names(df)

narwhals/_selectors.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import re
66
from functools import partial
77
from typing import TYPE_CHECKING
8+
from typing import Any
89
from typing import Callable
910
from typing import Collection
1011
from typing import Generic
@@ -41,7 +42,7 @@
4142

4243

4344
SeriesT = TypeVar("SeriesT", bound="CompliantSeries")
44-
FrameT = TypeVar("FrameT", bound="CompliantDataFrame | CompliantLazyFrame")
45+
FrameT = TypeVar("FrameT", bound="CompliantDataFrame[Any] | CompliantLazyFrame")
4546
SelectorOrExpr: TypeAlias = (
4647
"CompliantSelector[FrameT, SeriesT] | CompliantExpr[FrameT, SeriesT]"
4748
)
@@ -265,14 +266,16 @@ def names(df: FrameT) -> Sequence[str]:
265266
return self._to_expr() & other
266267

267268
def __invert__(self: Self) -> CompliantSelector[FrameT, SeriesT]:
268-
return self.selectors.all() - self
269+
return self.selectors.all() - self # type: ignore[no-any-return]
269270

270271
def __repr__(self: Self) -> str: # pragma: no cover
271272
s = f"depth={self._depth}, " if is_tracks_depth(self._implementation) else ""
272273
return f"{type(self).__name__}({s}function_name={self._function_name})"
273274

274275

275276
def _eval_lhs_rhs(
276-
df: CompliantDataFrame | CompliantLazyFrame, lhs: CompliantExpr, rhs: CompliantExpr
277+
df: CompliantDataFrame[Any] | CompliantLazyFrame,
278+
lhs: CompliantExpr[Any, Any],
279+
rhs: CompliantExpr[Any, Any],
277280
) -> tuple[Sequence[str], Sequence[str]]:
278281
return lhs._evaluate_output_names(df), rhs._evaluate_output_names(df)

narwhals/_spark_like/dataframe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def collect(
163163
self: Self,
164164
backend: ModuleType | Implementation | str | None,
165165
**kwargs: Any,
166-
) -> CompliantDataFrame:
166+
) -> CompliantDataFrame[Any]:
167167
if backend is Implementation.PANDAS:
168168
import pandas as pd # ignore-banned-import
169169

narwhals/typing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def schema(self) -> Mapping[str, DType]: ...
9393

9494

9595
CompliantFrameT = TypeVar(
96-
"CompliantFrameT", bound="CompliantDataFrame | CompliantLazyFrame"
96+
"CompliantFrameT", bound="CompliantDataFrame[Any] | CompliantLazyFrame"
9797
)
9898

9999

narwhals/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,7 @@ def dtype_matches_time_unit_and_time_zone(
13091309

13101310

13111311
def get_column_names(
1312-
df: NativeFrame | CompliantDataFrame | CompliantLazyFrame,
1312+
df: NativeFrame | CompliantDataFrame[Any] | CompliantLazyFrame,
13131313
) -> Sequence[str]:
13141314
return df.columns
13151315

@@ -1319,7 +1319,9 @@ def _hasattr_static(obj: Any, attr: str) -> bool:
13191319
return getattr_static(obj, attr, sentinel) is not sentinel
13201320

13211321

1322-
def is_compliant_dataframe(obj: Any) -> TypeIs[CompliantDataFrame]:
1322+
def is_compliant_dataframe(
1323+
obj: Any | CompliantDataFrame[CompliantSeriesT_co],
1324+
) -> TypeIs[CompliantDataFrame[CompliantSeriesT_co]]:
13231325
return _hasattr_static(obj, "__narwhals_dataframe__")
13241326

13251327

0 commit comments

Comments
 (0)