diff --git a/narwhals/_compliant/expr.py b/narwhals/_compliant/expr.py index 8e6e8b5fbb..32bf478a1c 100644 --- a/narwhals/_compliant/expr.py +++ b/narwhals/_compliant/expr.py @@ -27,7 +27,7 @@ LazyExprT, NativeExprT, ) -from narwhals._typing_compat import Protocol38, deprecated +from narwhals._typing_compat import deprecated from narwhals._utils import _StoresCompliant from narwhals.dependencies import get_numpy, is_numpy_array @@ -66,7 +66,7 @@ def between(self, *args: Any, **kwds: Any) -> Any: ... def isin(self, *args: Any, **kwds: Any) -> Any: ... -class CompliantExpr(Protocol38[CompliantFrameT, CompliantSeriesOrNativeExprT_co]): +class CompliantExpr(Protocol[CompliantFrameT, CompliantSeriesOrNativeExprT_co]): _implementation: Implementation _version: Version _evaluate_output_names: EvalNames[CompliantFrameT] @@ -264,7 +264,7 @@ def struct(self) -> StructNamespace[Self]: ... class DepthTrackingExpr( CompliantExpr[CompliantFrameT, CompliantSeriesOrNativeExprT_co], - Protocol38[CompliantFrameT, CompliantSeriesOrNativeExprT_co], + Protocol[CompliantFrameT, CompliantSeriesOrNativeExprT_co], ): _depth: int _function_name: str @@ -302,7 +302,7 @@ def __repr__(self) -> str: # pragma: no cover class EagerExpr( DepthTrackingExpr[EagerDataFrameT, EagerSeriesT], - Protocol38[EagerDataFrameT, EagerSeriesT], + Protocol[EagerDataFrameT, EagerSeriesT], ): _call: EvalSeries[EagerDataFrameT, EagerSeriesT] _scalar_kwargs: ScalarKwargs @@ -899,7 +899,7 @@ def struct(self) -> EagerExprStructNamespace[Self]: # mypy thinks `NativeExprT` should be covariant, pyright thinks it should be invariant class LazyExpr( # type: ignore[misc] CompliantExpr[CompliantLazyFrameT, NativeExprT], - Protocol38[CompliantLazyFrameT, NativeExprT], + Protocol[CompliantLazyFrameT, NativeExprT], ): def _with_alias_output_names(self, func: AliasNames | None, /) -> Self: ... def alias(self, name: str) -> Self: diff --git a/narwhals/_compliant/group_by.py b/narwhals/_compliant/group_by.py index 97a554b26e..1e1bd7b2a3 100644 --- a/narwhals/_compliant/group_by.py +++ b/narwhals/_compliant/group_by.py @@ -1,7 +1,7 @@ from __future__ import annotations import re -from typing import TYPE_CHECKING, Any, Callable, ClassVar, TypeVar +from typing import TYPE_CHECKING, Any, Callable, ClassVar, Protocol, TypeVar from narwhals._compliant.typing import ( CompliantDataFrameAny, @@ -14,7 +14,6 @@ EagerExprT_contra, NarwhalsAggregation, ) -from narwhals._typing_compat import Protocol38 from narwhals._utils import is_sequence_of if TYPE_CHECKING: @@ -33,7 +32,7 @@ _RE_LEAF_NAME: re.Pattern[str] = re.compile(r"(\w+->)") -class CompliantGroupBy(Protocol38[CompliantFrameT_co, CompliantExprT_contra]): +class CompliantGroupBy(Protocol[CompliantFrameT_co, CompliantExprT_contra]): _compliant_frame: Any @property @@ -54,14 +53,14 @@ def agg(self, *exprs: CompliantExprT_contra) -> CompliantFrameT_co: ... class DataFrameGroupBy( CompliantGroupBy[CompliantDataFrameT_co, CompliantExprT_contra], - Protocol38[CompliantDataFrameT_co, CompliantExprT_contra], + Protocol[CompliantDataFrameT_co, CompliantExprT_contra], ): def __iter__(self) -> Iterator[tuple[Any, CompliantDataFrameT_co]]: ... class ParseKeysGroupBy( CompliantGroupBy[CompliantFrameT_co, CompliantExprT_contra], - Protocol38[CompliantFrameT_co, CompliantExprT_contra], + Protocol[CompliantFrameT_co, CompliantExprT_contra], ): def _parse_keys( self, @@ -118,7 +117,7 @@ def _temporary_name(key: str) -> str: class DepthTrackingGroupBy( ParseKeysGroupBy[CompliantFrameT_co, DepthTrackingExprT_contra], - Protocol38[CompliantFrameT_co, DepthTrackingExprT_contra, NativeAggregationT_co], + Protocol[CompliantFrameT_co, DepthTrackingExprT_contra, NativeAggregationT_co], ): """`CompliantGroupBy` variant, deals with `Eager` and other backends that utilize `CompliantExpr._depth`.""" @@ -175,5 +174,5 @@ class EagerGroupBy( CompliantDataFrameT_co, EagerExprT_contra, NativeAggregationT_co ], DataFrameGroupBy[CompliantDataFrameT_co, EagerExprT_contra], - Protocol38[CompliantDataFrameT_co, EagerExprT_contra, NativeAggregationT_co], + Protocol[CompliantDataFrameT_co, EagerExprT_contra, NativeAggregationT_co], ): ... diff --git a/narwhals/_compliant/selectors.py b/narwhals/_compliant/selectors.py index d414970fa4..8e318dc675 100644 --- a/narwhals/_compliant/selectors.py +++ b/narwhals/_compliant/selectors.py @@ -7,7 +7,6 @@ from typing import TYPE_CHECKING, Protocol, TypeVar, overload from narwhals._compliant.expr import CompliantExpr -from narwhals._typing_compat import Protocol38 from narwhals._utils import ( _parse_time_unit_and_time_zone, dtype_matches_time_unit_and_time_zone, @@ -197,7 +196,7 @@ def _iter_columns_dtypes(self, df: LazyFrameT, /) -> Iterator[tuple[ExprT, DType class CompliantSelector( - CompliantExpr[FrameT, SeriesOrExprT], Protocol38[FrameT, SeriesOrExprT] + CompliantExpr[FrameT, SeriesOrExprT], Protocol[FrameT, SeriesOrExprT] ): _call: EvalSeries[FrameT, SeriesOrExprT] _function_name: str diff --git a/narwhals/_compliant/when_then.py b/narwhals/_compliant/when_then.py index d752c2676e..bc4db69382 100644 --- a/narwhals/_compliant/when_then.py +++ b/narwhals/_compliant/when_then.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, TypeVar, cast +from typing import TYPE_CHECKING, Any, Protocol, TypeVar, cast from narwhals._compliant.expr import CompliantExpr from narwhals._compliant.typing import ( @@ -13,7 +13,6 @@ LazyExprAny, NativeSeriesT, ) -from narwhals._typing_compat import Protocol38 if TYPE_CHECKING: from collections.abc import Sequence @@ -39,7 +38,7 @@ """Anything that is convertible into a `CompliantExpr`.""" -class CompliantWhen(Protocol38[FrameT, SeriesT, ExprT]): +class CompliantWhen(Protocol[FrameT, SeriesT, ExprT]): _condition: ExprT _then_value: IntoExpr[SeriesT, ExprT] _otherwise_value: IntoExpr[SeriesT, ExprT] | None @@ -71,7 +70,7 @@ def from_expr(cls, condition: ExprT, /, *, context: _LimitedContext) -> Self: class CompliantThen( - CompliantExpr[FrameT, SeriesT], Protocol38[FrameT, SeriesT, ExprT, WhenT_contra] + CompliantExpr[FrameT, SeriesT], Protocol[FrameT, SeriesT, ExprT, WhenT_contra] ): _call: EvalSeries[FrameT, SeriesT] _when_value: CompliantWhen[FrameT, SeriesT, ExprT] @@ -99,7 +98,7 @@ def otherwise(self, otherwise: IntoExpr[SeriesT, ExprT], /) -> ExprT: class EagerWhen( CompliantWhen[EagerDataFrameT, EagerSeriesT, EagerExprT], - Protocol38[EagerDataFrameT, EagerSeriesT, EagerExprT, NativeSeriesT], + Protocol[EagerDataFrameT, EagerSeriesT, EagerExprT, NativeSeriesT], ): def _if_then_else( self, diff --git a/narwhals/_sql/expr.py b/narwhals/_sql/expr.py index 1467017b0b..80b0d510f8 100644 --- a/narwhals/_sql/expr.py +++ b/narwhals/_sql/expr.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Callable, Literal, cast +from typing import TYPE_CHECKING, Any, Callable, Literal, Protocol, cast from narwhals._compliant.expr import LazyExpr from narwhals._compliant.typing import ( @@ -16,7 +16,6 @@ combine_evaluate_output_names, ) from narwhals._sql.typing import SQLLazyFrameT -from narwhals._typing_compat import Protocol38 from narwhals._utils import Implementation, Version, not_implemented if TYPE_CHECKING: @@ -29,9 +28,7 @@ from narwhals.typing import PythonLiteral, RankMethod -class SQLExpr( - LazyExpr[SQLLazyFrameT, NativeExprT], Protocol38[SQLLazyFrameT, NativeExprT] -): +class SQLExpr(LazyExpr[SQLLazyFrameT, NativeExprT], Protocol[SQLLazyFrameT, NativeExprT]): _call: EvalSeries[SQLLazyFrameT, NativeExprT] _evaluate_output_names: EvalNames[SQLLazyFrameT] _alias_output_names: AliasNames | None diff --git a/narwhals/_sql/group_by.py b/narwhals/_sql/group_by.py index 9e5354e581..58e236f33e 100644 --- a/narwhals/_sql/group_by.py +++ b/narwhals/_sql/group_by.py @@ -1,11 +1,10 @@ from __future__ import annotations -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Protocol from narwhals._compliant.group_by import CompliantGroupBy, ParseKeysGroupBy from narwhals._compliant.typing import CompliantLazyFrameT_co, NativeExprT_co from narwhals._sql.typing import SQLExprT_contra -from narwhals._typing_compat import Protocol38 if TYPE_CHECKING: from collections.abc import Iterable, Iterator @@ -14,7 +13,7 @@ class SQLGroupBy( ParseKeysGroupBy[CompliantLazyFrameT_co, SQLExprT_contra], CompliantGroupBy[CompliantLazyFrameT_co, SQLExprT_contra], - Protocol38[CompliantLazyFrameT_co, SQLExprT_contra, NativeExprT_co], + Protocol[CompliantLazyFrameT_co, SQLExprT_contra, NativeExprT_co], ): _keys: list[str] _output_key_names: list[str] diff --git a/narwhals/_sql/when_then.py b/narwhals/_sql/when_then.py index 70ff36c016..7c34298875 100644 --- a/narwhals/_sql/when_then.py +++ b/narwhals/_sql/when_then.py @@ -1,11 +1,10 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Callable +from typing import TYPE_CHECKING, Callable, Protocol from narwhals._compliant.typing import CompliantLazyFrameT, NativeExprT from narwhals._compliant.when_then import CompliantThen, CompliantWhen from narwhals._sql.typing import SQLExprT -from narwhals._typing_compat import Protocol38 if TYPE_CHECKING: from collections.abc import Sequence @@ -20,7 +19,7 @@ class SQLWhen( CompliantWhen[CompliantLazyFrameT, NativeExprT, SQLExprT], - Protocol38[CompliantLazyFrameT, NativeExprT, SQLExprT], + Protocol[CompliantLazyFrameT, NativeExprT, SQLExprT], ): when: Callable[..., NativeExprT] lit: Callable[..., NativeExprT] @@ -82,7 +81,7 @@ class SQLThen( SQLExprT, SQLWhen[CompliantLazyFrameT, NativeExprT, SQLExprT], ], - Protocol38[CompliantLazyFrameT, NativeExprT, SQLExprT], + Protocol[CompliantLazyFrameT, NativeExprT, SQLExprT], ): _window_function: WindowFunction[CompliantLazyFrameT, NativeExprT] | None diff --git a/narwhals/_typing_compat.py b/narwhals/_typing_compat.py index ebf3dc16ec..47cbf3464a 100644 --- a/narwhals/_typing_compat.py +++ b/narwhals/_typing_compat.py @@ -4,9 +4,6 @@ Import from here to avoid introducing a runtime dependency on [`typing_extensions`] ## Notes -- `Protocol38` - - https://github.com/narwhals-dev/narwhals/pull/2064#discussion_r1965921386 - - https://github.com/narwhals-dev/narwhals/pull/2294#discussion_r2014534830 - `TypeVar` defaults - https://typing.python.org/en/latest/spec/generics.html#type-parameter-defaults - https://peps.python.org/pep-0696/ @@ -25,7 +22,7 @@ from typing import TYPE_CHECKING, Any if TYPE_CHECKING: - from typing import Callable, Protocol as Protocol38 + from typing import Callable if sys.version_info >= (3, 13): from typing import TypeVar @@ -85,9 +82,5 @@ def assert_never(arg: Never, /) -> Never: ) raise AssertionError(msg) - # TODO @dangotbanned: Remove after dropping `3.8` (#2084) - # - https://github.com/narwhals-dev/narwhals/pull/2064#discussion_r1965921386 - from typing import Protocol as Protocol38 - -__all__ = ["Protocol38", "TypeVar", "assert_never", "deprecated"] +__all__ = ["TypeVar", "assert_never", "deprecated"]