Skip to content
New issue

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

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

Already on GitHub? # to your account

Add pathlike support to stream dump #2067

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

EmilianoJordan
Copy link

Adds support for Path and Pathlike objects to TemplateStream.dump.

My understanding of the existing code is:

  1. Strings are treated as file paths
  2. Other valid objects implement a write(value: bytes) -> None or writelines(Iterable[bytes]) -> None method.
  3. Invalid objects raise an AttributeError, e.g. AttributeError: 'NoneType' object has no attribute 'write'

My change would modify the behavior to:

  1. Any object that the builtin open can handle as a file path is a valid file path. This includes the requested pathlib.Path and PathLike objects.
  2. This functionality is unchanged.
  3. Invalid objects still raise an AttributeError with a slightly more informative message AttributeError: 'NoneType' object has no attribute 'write' or 'writelines'

Possible Breaking Changes (No tests guarantee this functionality):

  1. Any object that isn't a string but open is capable of handling.
  2. 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

  1. This is my first PR for a pallets project. Any feedback is welcome.
  2. The tests are very comprehensive, and may be too much for the code base. Happy to scale them back in any way.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

template.stream().dump( ) could take a path like object.
1 participant