Skip to content

Commit

Permalink
Refactoring type hints to avoid use of Self
Browse files Browse the repository at this point in the history
Various other type improvements
  • Loading branch information
nathanjmcdougall committed Aug 20, 2024
1 parent 5b57805 commit 549679a
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pins/_adaptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

import json
from abc import abstractmethod
from typing import TYPE_CHECKING, Any, ClassVar, TypeAlias, overload

from typing_extensions import Self
from typing import TYPE_CHECKING, Any, ClassVar, TypeAlias, Union, overload

from ._databackend import AbstractBackend

if TYPE_CHECKING:
import pandas as pd

_PandasDataFrame: TypeAlias = pd.DataFrame
_DataFrame: TypeAlias = pd.DataFrame
_DataFrame: TypeAlias = Union[_PandasDataFrame,]

Check failure on line 13 in pins/_adaptors.py

View workflow job for this annotation

GitHub Actions / Run Pyright

Union requires two or more type arguments (reportInvalidTypeArguments)


class _AbstractPandasFrame(AbstractBackend):
Expand Down Expand Up @@ -99,7 +97,7 @@ def columns(self) -> list[Any]: ...
def shape(self) -> tuple[int, int]: ...

@abstractmethod
def head(self, n: int) -> Self: ...
def head(self, n: int) -> _DFAdaptor: ...

@property
def data_preview(self) -> str:
Expand All @@ -123,6 +121,8 @@ def _obj_name(self) -> str:


class _PandasAdaptor(_DFAdaptor):
_d: ClassVar[_PandasDataFrame]

def __init__(self, data: _AbstractPandasFrame) -> None:
super().__init__(data)

Expand All @@ -134,7 +134,7 @@ def columns(self) -> list[Any]:
def shape(self) -> tuple[int, int]:
return self._d.shape

def head(self, n: int) -> Self:
def head(self, n: int) -> _PandasAdaptor:
return _PandasAdaptor(self._d.head(n))

@overload
Expand Down

0 comments on commit 549679a

Please sign in to comment.