Support generic os.PathLike instead of pathlib.Path#11580
Conversation
|
direct use of |
|
@Cadair There is no guarantee that In contrast, |
|
That makes sense, but seems odd that class doesn't have a non-magic method for doing that. |
|
Nice! I think this is a great idea, and is almost a bug fix. Could you add a test, even taken from your original issue? |
|
Thanks! Agree with @adrn that new tests are needed to cover the new changes. |
|
Also perhaps add an example in user-facing doc? Otherwise, this new improvement is hard to discover. |
Indeed, but then you should use |
|
Thank you for the suggestions! I now fixed the changelog RST, and replaced |
|
Hello @olebole 👋! It looks like you've made some changes in your pull request, so I've checked the code again for style. There are no PEP8 style issues with this pull request - thanks! 🎉 Comment last updated at 2021-04-16 16:18:40 UTC |
|
Two approvals would seem good enough. Let's get it in. Thanks, @olebole! |
|
Oh no! Stuff in the docs should now be "path-like", see #11118. |
|
|
||
| from os import PathLike | ||
| path_like = (str, PathLike) | ||
| path_like = (str, os.PathLike) |
There was a problem hiding this comment.
according to https://docs.python.org/3/glossary.html#term-path-like-object, path-like should include bytes
There was a problem hiding this comment.
The three components of python's path-like are string, byte, os.PathLike
| _identifiers = OrderedDict() | ||
|
|
||
| PATH_TYPES = (str, pathlib.Path) | ||
| PATH_TYPES = (str, os.PathLike) |
|
I've added this as a TODO in the above issue |
Description
This PR replaces all appearances of
with
Rationale: In Python, paths are not necessarily strings or
pathlib.Pathobjects, but anything that isos.Pathlikeis acceptable inopen(). One use case here is a specific path like object that retrieves/builds a file just before it is opened (f.e. for a cache).The canonical way to access the file path on the OS is then done by
__fspath__(), not bystr().Fixes #11579