jinja
jinja copied to clipboard
Add pathlike support to stream dump
Adds support for Path and Pathlike objects to TemplateStream.dump.
My understanding of the existing code is:
- Strings are treated as file paths
- Other valid objects implement a
write(value: bytes) -> Noneorwritelines(Iterable[bytes]) -> Nonemethod. - Invalid objects raise an
AttributeError, e.g.AttributeError: 'NoneType' object has no attribute 'write'
My change would modify the behavior to:
- Any object that the builtin
opencan handle as a file path is a valid file path. This includes the requestedpathlib.Pathand PathLike objects. - This functionality is unchanged.
- Invalid objects still raise an
AttributeErrorwith a slightly more informative messageAttributeError: 'NoneType' object has no attribute 'write' or 'writelines'
Possible Breaking Changes (No tests guarantee this functionality):
- Any object that isn't a string but
openis capable of handling. - Any equality checks on the error message for the
AttributeError
This does not address #1983 the only changes to the typing is the inclusion of the full set of types that open implements.
fixes #2039
Desired Feedback
- This is my first PR for a pallets project. Any feedback is welcome.
- The tests are very comprehensive, and may be too much for the code base. Happy to scale them back in any way.