-
-
Notifications
You must be signed in to change notification settings - Fork 19.4k
Description
Feature Type
-
Adding new functionality to pandas
-
Changing existing functionality in pandas
-
Removing existing functionality in pandas
Problem Description
I would like to pass an io.IOBase (or a subclass, such as botocore.response.StreamingBody) to functions that accept one of the various "buffer" classes (ReadBuffer, ReadCsvBuffer, etc.)
Currently, this does not type-check (or, at least not with Pyright), because the BaseBuffer protocol defines a mode property:
Lines 271 to 274 in 1be2637
| @property | |
| def mode(self) -> str: | |
| # for _get_filepath_or_buffer | |
| ... |
Type "IOBase" is not assignable to declared type "ReadCsvBuffer[bytes]"
"IOBase" is incompatible with protocol "ReadCsvBuffer[bytes]"
"mode" is not present
Feature Description
AFAICT, the only place the BaseBuffer.mode property is accessed is this getattr call, which can handle the property not existing (due to the default value).
Lines 1196 to 1198 in 1be2637
| return isinstance(handle, _get_binary_io_classes()) or "b" in getattr( | |
| handle, "mode", mode | |
| ) |
Can we just remove the mode property from BaseBuffer, since (AFAICT) it's not actually required by any Pandas code that handles BaseBuffer instances (and/or instances of BaseBuffer subclasses)?
Alternative Solutions
If python/typing#601 ever becomes a reality, BaseBuffer.mode could be marked as an "optional" property.
Additional Context
No response