Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Pathlike objects for file arguments #337

Merged
merged 7 commits into from Feb 12, 2022

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.

src/lxml/apihelpers.pxi Outdated Show resolved Hide resolved
src/lxml/includes/etree_defs.h Outdated Show resolved Hide resolved
src/lxml/includes/etree_defs.h Outdated Show resolved Hide resolved
@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
src/lxml/apihelpers.pxi Outdated Show resolved Hide resolved
src/lxml/tests/test_dtd.py Outdated Show resolved Hide resolved
src/lxml/includes/etree_defs.h Outdated Show resolved Hide resolved
src/lxml/python.pxd Outdated Show resolved Hide resolved
@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
2 participants