Accept Pathlike objects (eg. pathlib.Path) in Py3.6+ #990
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PEP-519 (Py3.6+ / PyPy 7.3+) adds a [file system path protocol[(https://www.python.org/dev/peps/pep-0519/) via
Object.__fspath__()
, and is supported bypathlib
/os
/open()
/etc. This PR adds support for acceptingpathlib.Path
objects natively in Pygit2.hasattr(value, '__fspath__')
to provide Py3.5 compatibility, then call it to get a str/bytes representation.PyUnicode_FSConverter
when parsing function arguments (it handles Pathlike objects), orPyOS_FSPath()
when available (ie. not Py3.5).os.fspath()
/PyOS_FSPath()
return a str/bytes argument unchanged, behaviour-wise it's the same. Cleaning this up might sit with Consistent interface to get text and bytes #895?Adds a pile of
*_aspath()
tests under Py3.6+ to wherever we seem to accept paths. I'm sure I've missed some but we can sort that along the way.