[Python-ideas] Introduce typing.SupportsFsPath
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
def __fspath__(self) -> AnyStr: ...
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas