diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d41d091d03bd7..8ff7526b87521 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -102,7 +102,7 @@ repos: types: [python] stages: [manual] additional_dependencies: &pyright_dependencies - - pyright@1.1.264 + - pyright@1.1.276 - id: pyright_reportGeneralTypeIssues # note: assumes python env is setup and activated name: pyright reportGeneralTypeIssues diff --git a/pandas/_typing.py b/pandas/_typing.py index 5c22baa4bd42e..dad5ffd48caa8 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -198,10 +198,6 @@ def mode(self) -> str: # for _get_filepath_or_buffer ... - def fileno(self) -> int: - # for _MMapWrapper - ... - def seek(self, __offset: int, __whence: int = ...) -> int: # with one argument: gzip.GzipFile, bz2.BZ2File # with two arguments: zip.ZipFile, read_sas @@ -217,7 +213,7 @@ def tell(self) -> int: class ReadBuffer(BaseBuffer, Protocol[AnyStr_cov]): - def read(self, __n: int | None = ...) -> AnyStr_cov: + def read(self, __n: int = ...) -> AnyStr_cov: # for BytesIOWrapper, gzip.GzipFile, bz2.BZ2File ... @@ -233,7 +229,7 @@ def flush(self) -> Any: class ReadPickleBuffer(ReadBuffer[bytes], Protocol): - def readline(self) -> AnyStr_cov: + def readline(self) -> bytes: ... @@ -247,6 +243,10 @@ def __iter__(self) -> Iterator[AnyStr_cov]: # for engine=python ... + def fileno(self) -> int: + # for _MMapWrapper + ... + def readline(self) -> AnyStr_cov: # for engine=python ... diff --git a/pandas/io/common.py b/pandas/io/common.py index 64e703572f2bf..265de02dd5d6b 100644 --- a/pandas/io/common.py +++ b/pandas/io/common.py @@ -50,6 +50,7 @@ CompressionOptions, FilePath, ReadBuffer, + ReadCsvBuffer, StorageOptions, WriteBuffer, ) @@ -1106,6 +1107,9 @@ def _maybe_memory_map( if not memory_map: return handle, memory_map, handles + # mmap used by only read_csv + handle = cast(ReadCsvBuffer, handle) + # need to open the file first if isinstance(handle, str): handle = open(handle, "rb") diff --git a/pandas/io/xml.py b/pandas/io/xml.py index 71d19b7861fc2..bea04078cf556 100644 --- a/pandas/io/xml.py +++ b/pandas/io/xml.py @@ -712,10 +712,7 @@ def get_data_from_filepath( storage_options=storage_options, ) as handle_obj: filepath_or_buffer = ( - # error: Incompatible types in assignment (expression has type - # "Union[str, IO[str]]", variable has type "Union[Union[str, - # PathLike[str]], bytes, ReadBuffer[bytes], ReadBuffer[str]]") - handle_obj.handle.read() # type: ignore[assignment] + handle_obj.handle.read() if hasattr(handle_obj.handle, "read") else handle_obj.handle )