Skip to content

Should FilePathorBuffer use os.PathLike instead of pathlib.Path? #37979

Closed
@willfrey

Description

@willfrey

The documentation for pandas.read_csv(...) states that it can support anything that adheres to the os.PathLike protocol, but the definition of FilePathOrBuffer is too strict.

FilePathOrBuffer = Union[Path, FileOrBuffer[T]]

where Path is a pathlib.Path object.

Could this be changed to use os.PathLike[str] or just os.PathLike?

from os import PathLike

FilePathOrBuffer = Union["PathLike[str]", FileOrBuffer]

PathLike is in quotes because PathLike only supports __class_getitem__ for Python 3.9 and later and PathLike alone might be too broad, assuming you don't want to support byte-encoded paths.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Typingtype annotations, mypy/pyright type checking

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions