Skip to content

Add PathLike to typing #402

@ilevkivskyi

Description

@ilevkivskyi

While thinking about protocols, it came to my mind that we could add PathLike to typing, also we could make it a (runtime) protocol class. As I understand PEP 519, it could be typed like this:

S = TypeVar('S', bound=Union[str, bytes])
class PathLike(Generic[S], extra=os.PathLike): # or Protocol[S] in future
    def __fspath__(self) -> S:
        ...

So that there will be three allowed types: PathLike[str], PathLike[bytes], and PathLike[Union[str, bytes]]. Or we actually don't need PathLike[Union[str, bytes]]? In this case we could just use AnyStr instead of S.

CC @brettcannon

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions