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.)

On Mon, Oct 8, 2018 at 3:10 PM <> wrote:

Since __fspath__ was introduced in PEP 519 it is possible to create
object classes that are representing file system paths.
But there is no corresponding type object in the "typing" module. Thus I
cannot specify functions, that accept any kind of object which supports
the __fspath__ protocol.

Please note that "Path" is not a replacement for "SupportsFsPath", since
the concept of PEP 519 is, that I could implement new objects (without
dependency to "Path")
that are implementing the __fspath__ protocol.

Python-ideas mailing list
Code of Conduct:

--Guido van Rossum (