Skip to content
/ lxml Public

Allow Pathlike objects for file arguments#337

Merged
scoder merged 7 commits intolxml:masterfrom
janssenhenning:accept-pathlike-source
Feb 12, 2022
Merged

Allow Pathlike objects for file arguments#337
scoder merged 7 commits intolxml:masterfrom
janssenhenning:accept-pathlike-source

Conversation

@janssenhenning
Copy link
Contributor

Added `_isStringOrPathLike` typecheck which checks for the existence
of `__fspath__` for python 3.6+. `_encodeFilename` in apihelpers uses
`os.fspath` to resolve thes paths
`iterparse` already allowed it, but a test is added.
Copy link
Member

@scoder scoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, very nice. I think we should backport it, though. There is no reason why this couldn't work in Py<3.6 if someone cares to define __fspath__ on some object, such as a backported pathlib.

@scoder scoder added the feature label Jan 27, 2022
instead of checking for __fspath__ multiple times a cython function
_getFSPathOrObject is added which calls the __fspath__ attribute if
it exists

For python 3.6+ this function uses PyOS_FSPath
@scoder scoder merged commit 1e36660 into lxml:master Feb 12, 2022
@scoder
Copy link
Member

scoder commented Feb 12, 2022

Thanks!

@janssenhenning janssenhenning deleted the accept-pathlike-source branch February 17, 2022 12:26
janssenhenning added a commit to JuDFTteam/masci-tools that referenced this pull request Feb 17, 2022
for all of the API
lxml/lxml#337
This allows to eliminate some corner cases in the fleur parser
janssenhenning added a commit to JuDFTteam/masci-tools that referenced this pull request Feb 23, 2022
for all of the API
lxml/lxml#337
This allows to eliminate some corner cases in the fleur parser
janssenhenning added a commit to JuDFTteam/masci-tools that referenced this pull request Feb 25, 2022
for all of the API
lxml/lxml#337
This allows to eliminate some corner cases in the fleur parser
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants