On Tue, 9 Oct 2018 at 03:13, Guido van Rossum <gu...@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: ...

--
Ivan
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to