Skip to content

Support PathLike image and package file inputs - #1123

Open
AlexanderWillner wants to merge 1 commit into
scanny:masterfrom
AlexanderWillner:codex/pathlike-file-inputs
Open

Support PathLike image and package file inputs#1123
AlexanderWillner wants to merge 1 commit into
scanny:masterfrom
AlexanderWillner:codex/pathlike-file-inputs

Conversation

@AlexanderWillner

Copy link
Copy Markdown

Summary

  • accept os.PathLike inputs in Image.from_file()
  • accept os.PathLike inputs in Part._blob_from_file()
  • add regression coverage for pathlib.Path file inputs

Why

python-pptx currently treats only str values as file paths in these helpers. Passing pathlib.Path falls through to the file-like branch and raises an AttributeError on .seek/.read assumptions.

Testing

  • PYTHONPATH=src python -m pytest tests/parts/test_image.py -q
  • PYTHONPATH=src python -m pytest -o filterwarnings=ignore::pyparsing.warnings.PyparsingDeprecationWarning tests/opc/test_package.py tests/test_package.py -q
  • smoke-tested slide.shapes.add_picture(Path(...), ...) with a JPEG fixture

lofcz added a commit to lofcz/python-pptx2 that referenced this pull request Aug 30, 2026
`pathlib.Path` (any `os.PathLike`) previously raised TypeError from
`Image.from_file()` and was misrouted as a stream by the package
reader's `_PhysPkgReader.factory()`. Path-like inputs are now
normalized with `os.fspath()` at the boundaries, keeping the `str`
fast-path and file-like behavior unchanged.

Covered entry points: `Presentation()` open, `Presentation.save()`
(package and part save), `Image.from_file()`,
`shapes.add_picture()`, and picture-placeholder
`insert_picture()`. Type hints along the forwarding chain are
widened to `str | os.PathLike[str] | IO[bytes]`.

Port of scanny#1123 by AlexanderWillner.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant