Update open, os.fspath, os.fsencode, os.fsdecode, pathlib.PurePath and pathlib.Path stubs due to PEP-519 by sproshev · Pull Request #991 · python/typeshed (original) (raw)

This change looks good to me but there's a lot more to be done in relation to PEP 519.

First, many additional functions should be updated to accept os.PathLike in addition to str for paths. We should maybe add a type alias (typing.Path?) for Union[str, os.PathLike] to typing, because otherwise we'll have to put a lot of version checks for 3.6 in various places.

Also, os.PathLike should perhaps be generic over AnyStr to express the bytes/str situation more precisely. For example, the Path constructor only accepts os.PathLike[str], not os.PathLike[bytes]. On the other hand, most use cases for Paths probably don't care about bytes paths, so maybe we don't need this complication.

Anyway, those issues are outside the scope of this PR. I'll think about them more and maybe write up a proposal.