[Python-ideas] Introduce typing.SupportsFsPath

Ivan Levkivskyi levkivskyi at gmail.com
Tue Oct 9 06:16:00 EDT 2018

On Tue, 9 Oct 2018 at 03:13, Guido van Rossum <guido at python.org> wrote:

> In typeshed there is os.PathLike which is close. You should be able to use
> Union[str, os.PathLike[str]] for what you want (or define an alias).
> We generally don't want to add more things to typing that aren't closely
> related to the type system. (Adding the io and re classes was already less
> than ideal, and we don't want to do more of those.)

The problem however is that `PathLike` is not a protocol in typeshed. This
should be updated when protocols will be official. Until that, you can just
easily define your own protocol:

from typing import AnyStr
from typing_extensions import Protocol

class PathLike(Protocol[AnyStr]):
    def __fspath__(self) -> AnyStr: ...

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20181009/90368c5a/attachment-0001.html>

More information about the Python-ideas mailing list