Skip to content

Commit 71558d9

Browse files
authored
TYP: fix ReadPickleBuffer (#48144)
* TYP: fix ReadPickleBuffer * require fileno only for ReadCsvBuffer * fix comment * bump pyright * pyright
1 parent c368c32 commit 71558d9

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ repos:
102102
types: [python]
103103
stages: [manual]
104104
additional_dependencies: &pyright_dependencies
105-
105+
106106
- id: pyright_reportGeneralTypeIssues
107107
# note: assumes python env is setup and activated
108108
name: pyright reportGeneralTypeIssues

pandas/_typing.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,6 @@ def mode(self) -> str:
198198
# for _get_filepath_or_buffer
199199
...
200200

201-
def fileno(self) -> int:
202-
# for _MMapWrapper
203-
...
204-
205201
def seek(self, __offset: int, __whence: int = ...) -> int:
206202
# with one argument: gzip.GzipFile, bz2.BZ2File
207203
# with two arguments: zip.ZipFile, read_sas
@@ -217,7 +213,7 @@ def tell(self) -> int:
217213

218214

219215
class ReadBuffer(BaseBuffer, Protocol[AnyStr_cov]):
220-
def read(self, __n: int | None = ...) -> AnyStr_cov:
216+
def read(self, __n: int = ...) -> AnyStr_cov:
221217
# for BytesIOWrapper, gzip.GzipFile, bz2.BZ2File
222218
...
223219

@@ -233,7 +229,7 @@ def flush(self) -> Any:
233229

234230

235231
class ReadPickleBuffer(ReadBuffer[bytes], Protocol):
236-
def readline(self) -> AnyStr_cov:
232+
def readline(self) -> bytes:
237233
...
238234

239235

@@ -247,6 +243,10 @@ def __iter__(self) -> Iterator[AnyStr_cov]:
247243
# for engine=python
248244
...
249245

246+
def fileno(self) -> int:
247+
# for _MMapWrapper
248+
...
249+
250250
def readline(self) -> AnyStr_cov:
251251
# for engine=python
252252
...

pandas/io/common.py

+4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
CompressionOptions,
5151
FilePath,
5252
ReadBuffer,
53+
ReadCsvBuffer,
5354
StorageOptions,
5455
WriteBuffer,
5556
)
@@ -1106,6 +1107,9 @@ def _maybe_memory_map(
11061107
if not memory_map:
11071108
return handle, memory_map, handles
11081109

1110+
# mmap used by only read_csv
1111+
handle = cast(ReadCsvBuffer, handle)
1112+
11091113
# need to open the file first
11101114
if isinstance(handle, str):
11111115
handle = open(handle, "rb")

pandas/io/xml.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -712,10 +712,7 @@ def get_data_from_filepath(
712712
storage_options=storage_options,
713713
) as handle_obj:
714714
filepath_or_buffer = (
715-
# error: Incompatible types in assignment (expression has type
716-
# "Union[str, IO[str]]", variable has type "Union[Union[str,
717-
# PathLike[str]], bytes, ReadBuffer[bytes], ReadBuffer[str]]")
718-
handle_obj.handle.read() # type: ignore[assignment]
715+
handle_obj.handle.read()
719716
if hasattr(handle_obj.handle, "read")
720717
else handle_obj.handle
721718
)

0 commit comments

Comments
 (0)