Skip to content

Add PathLike to typing #402

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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