Skip to content

Commit d066eb8

Browse files
committed
refactor: Replace duplicated stable typing
#3016 (comment)
1 parent 9acfd4e commit d066eb8

File tree

2 files changed

+7
-55
lines changed

2 files changed

+7
-55
lines changed

narwhals/stable/v1/typing.py

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,10 @@
33
from typing import TYPE_CHECKING, Any, Protocol, TypeVar, Union
44

55
if TYPE_CHECKING:
6-
import sys
7-
from collections.abc import Iterable, Sized
6+
from typing_extensions import TypeAlias
87

9-
from narwhals.stable.v1 import DataFrame, LazyFrame
10-
11-
if sys.version_info >= (3, 10):
12-
from typing import TypeAlias
13-
else:
14-
from typing_extensions import TypeAlias
15-
16-
from narwhals.stable.v1 import Expr, Series
17-
18-
# All dataframes supported by Narwhals have a
19-
# `columns` property. Their similarities don't extend
20-
# _that_ much further unfortunately...
21-
class NativeFrame(Protocol):
22-
@property
23-
def columns(self) -> Any: ...
24-
25-
def join(self, *args: Any, **kwargs: Any) -> Any: ...
26-
27-
class NativeDataFrame(Sized, NativeFrame, Protocol): ...
28-
29-
class NativeLazyFrame(NativeFrame, Protocol):
30-
def explain(self, *args: Any, **kwargs: Any) -> Any: ...
31-
32-
class NativeSeries(Sized, Iterable[Any], Protocol):
33-
def filter(self, *args: Any, **kwargs: Any) -> Any: ...
8+
from narwhals._native import NativeDataFrame, NativeLazyFrame, NativeSeries
9+
from narwhals.stable.v1 import DataFrame, Expr, LazyFrame, Series
3410

3511
class DataFrameLike(Protocol):
3612
def __dataframe__(self, *args: Any, **kwargs: Any) -> Any: ...

narwhals/stable/v2/typing.py

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,12 @@
11
from __future__ import annotations
22

3-
from typing import TYPE_CHECKING, Any, Protocol, TypeVar, Union
3+
from typing import TYPE_CHECKING, Any, TypeVar, Union
44

55
if TYPE_CHECKING:
6-
import sys
7-
from collections.abc import Iterable, Sized
6+
from typing_extensions import TypeAlias
87

9-
from narwhals.stable.v2 import DataFrame, LazyFrame
10-
11-
if sys.version_info >= (3, 10):
12-
from typing import TypeAlias
13-
else:
14-
from typing_extensions import TypeAlias
15-
16-
from narwhals.stable.v2 import Expr, Series
17-
18-
# All dataframes supported by Narwhals have a
19-
# `columns` property. Their similarities don't extend
20-
# _that_ much further unfortunately...
21-
class NativeFrame(Protocol):
22-
@property
23-
def columns(self) -> Any: ...
24-
25-
def join(self, *args: Any, **kwargs: Any) -> Any: ...
26-
27-
class NativeDataFrame(Sized, NativeFrame, Protocol): ...
28-
29-
class NativeLazyFrame(NativeFrame, Protocol):
30-
def explain(self, *args: Any, **kwargs: Any) -> Any: ...
31-
32-
class NativeSeries(Sized, Iterable[Any], Protocol):
33-
def filter(self, *args: Any, **kwargs: Any) -> Any: ...
8+
from narwhals._native import NativeDataFrame, NativeLazyFrame, NativeSeries
9+
from narwhals.stable.v2 import DataFrame, Expr, LazyFrame, Series
3410

3511

3612
IntoExpr: TypeAlias = Union["Expr", str, "Series[Any]"]

0 commit comments

Comments
 (0)