diff --git a/pandas/_typing.py b/pandas/_typing.py index dad5ffd48caa8..2f912e9d97ef5 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -188,8 +188,8 @@ PythonFuncType = Callable[[Any], Any] # filenames and file-like-objects -AnyStr_cov = TypeVar("AnyStr_cov", str, bytes, covariant=True) -AnyStr_con = TypeVar("AnyStr_con", str, bytes, contravariant=True) +AnyStr_co = TypeVar("AnyStr_co", str, bytes, covariant=True) +AnyStr_contra = TypeVar("AnyStr_contra", str, bytes, contravariant=True) class BaseBuffer(Protocol): @@ -212,14 +212,14 @@ def tell(self) -> int: ... -class ReadBuffer(BaseBuffer, Protocol[AnyStr_cov]): - def read(self, __n: int = ...) -> AnyStr_cov: +class ReadBuffer(BaseBuffer, Protocol[AnyStr_co]): + def read(self, __n: int = ...) -> AnyStr_co: # for BytesIOWrapper, gzip.GzipFile, bz2.BZ2File ... -class WriteBuffer(BaseBuffer, Protocol[AnyStr_con]): - def write(self, __b: AnyStr_con) -> Any: +class WriteBuffer(BaseBuffer, Protocol[AnyStr_contra]): + def write(self, __b: AnyStr_contra) -> Any: # for gzip.GzipFile, bz2.BZ2File ... @@ -238,8 +238,8 @@ def truncate(self, size: int | None = ...) -> int: ... -class ReadCsvBuffer(ReadBuffer[AnyStr_cov], Protocol): - def __iter__(self) -> Iterator[AnyStr_cov]: +class ReadCsvBuffer(ReadBuffer[AnyStr_co], Protocol): + def __iter__(self) -> Iterator[AnyStr_co]: # for engine=python ... @@ -247,7 +247,7 @@ def fileno(self) -> int: # for _MMapWrapper ... - def readline(self) -> AnyStr_cov: + def readline(self) -> AnyStr_co: # for engine=python ... diff --git a/pyproject.toml b/pyproject.toml index 8b7204af7c089..1ccf577538db7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -85,7 +85,6 @@ disable = [ "missing-module-docstring", "singleton-comparison", "too-many-lines", - "typevar-name-incorrect-variance", "ungrouped-imports", "unidiomatic-typecheck", "unnecessary-dunder-call",