Skip to content

[codex] support path-like image paths#1555

Open
Sean-Kenneth-Doherty wants to merge 1 commit into
python-openxml:masterfrom
Sean-Kenneth-Doherty:codex/support-pathlike-images
Open

[codex] support path-like image paths#1555
Sean-Kenneth-Doherty wants to merge 1 commit into
python-openxml:masterfrom
Sean-Kenneth-Doherty:codex/support-pathlike-images

Conversation

@Sean-Kenneth-Doherty
Copy link
Copy Markdown

Summary

  • accept os.PathLike image paths in the image loader used by Document.add_picture() and Run.add_picture()
  • update public image-path annotations and docs to mention path-like objects
  • add regression coverage for Image.from_file(Path(...))

Fixes #1544

Validation

  • uv run --with pytest --with ruff --with-editable . python -m pytest tests/image/test_image.py tests/test_document.py tests/text/test_run.py -q
  • uv run --with pytest --with ruff --with-editable . python -m ruff check src/docx/image/image.py src/docx/document.py src/docx/text/run.py src/docx/parts/story.py src/docx/package.py tests/image/test_image.py
  • uv run --with-editable . python - <<'PY' ... Document().add_picture(Path('tests/test_files/python-icon.png')) ... PY
  • git diff --check

Note: a targeted pyright run is not included as validation because the current project reports pre-existing strict-type errors in these files/tests before this change.

AI assistance: prepared with OpenAI Codex.

@Sean-Kenneth-Doherty Sean-Kenneth-Doherty marked this pull request as ready for review May 16, 2026 23:22
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.

Support for pathlib.Path

1 participant