Skip to content

Python Reader/Writer classes should accept Path/PathLike arguments #242

@naegelejd

Description

@naegelejd

All Python Readers, Writers, and CodedInputStream/CodedOutputStreams should accept os.PathLike in addition to the current types.

For example:

class CodedInputStream:
def __init__(
self,
stream: Union[BufferedReader, BytesIO, BinaryIO, str],
*,
buffer_size: int = 65536,
) -> None:
if isinstance(stream, str):
self._stream = open(stream, "rb")
self._owns_stream = True

The CodedInputStream will only open the stream if it is of type str, but it should accept any "path-like object".

So the type signature should also include os.PathLike, and the isinstance(stream, str) should be isinstance(stream, (str, os.PathLIke)).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions