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
jinja2 incompatibility with paths created using pathlib #870
Comments
Are python libraries supposed to accept pathlib Path objects in places where usually a string path is provided? If yes, a pull request (that does not break Python 2 compatibility!) would be appreciated. |
I don't know about 'supposed to', but pathlib seems to be picking up steam as an alternative to os.path. I will take a look to see if this change could be made without affecting Python 2 compatibility. |
PRs for this: #871, #874, #876. Please push new commits rather than new PRs for every review. However, I don't think we should be converting anything to string. We don't do anything with the paths that requires them to be a string. Python functions already know how to use The original issue was that |
Experienced the following crash today. {% include path %} where "path" is a pathlib.Path object, not a string. Rendering the template crashes: TypeError: 'PosixPath' object is not iterable Does this belong to this ticket? Many python 3 developers love pathlib (including myself). It would be great to make jinja2 pathlib-friendly. |
This issue also arises if a project uses pytest |
@dedekind, I believe that is also due to FileSystemLoader not supporting pathlib.Paths. It does belong here. |
As part of refactoring, I have been converting my application from using
os.path
topathlib
.However, it appears that
jinja2
is incompatible with paths created usingpathlib.Path
.For example, if
tdir
is apathlib
Path object, the following generates an error:jinja_environment = Environment(loader=FileSystemLoader(tdir), trim_blocks=False, lstrip_blocks=True)
,where the bottom of the error traceback is
If I convert
tdir
to a string, things work fine.jinja: v 2.10
python: v3.6.5
The text was updated successfully, but these errors were encountered: