From 549679afb6d798f48945e6ee168104e803b6b678 Mon Sep 17 00:00:00 2001 From: Nathan McDougall Date: Wed, 21 Aug 2024 10:16:09 +1200 Subject: [PATCH] Refactoring type hints to avoid use of Self Various other type improvements --- pins/_adaptors.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pins/_adaptors.py b/pins/_adaptors.py index 185e5f66..f7f6d768 100644 --- a/pins/_adaptors.py +++ b/pins/_adaptors.py @@ -2,9 +2,7 @@ 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 @@ -12,7 +10,7 @@ import pandas as pd _PandasDataFrame: TypeAlias = pd.DataFrame - _DataFrame: TypeAlias = pd.DataFrame + _DataFrame: TypeAlias = Union[_PandasDataFrame,] class _AbstractPandasFrame(AbstractBackend): @@ -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: @@ -123,6 +121,8 @@ def _obj_name(self) -> str: class _PandasAdaptor(_DFAdaptor): + _d: ClassVar[_PandasDataFrame] + def __init__(self, data: _AbstractPandasFrame) -> None: super().__init__(data) @@ -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