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