Skip to content

Docs: Add a diagram of pathlib path components - #159727

Merged
pganssle merged 3 commits into
python:mainfrom
pganssle:pathlib-component-diagram
Oct 20, 2026
Merged

pganssle merged 3 commits into
python:mainfrom
pganssle:pathlib-component-diagram

Conversation

@pganssle

@pganssle pganssle commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Add a diagram showing how parent, name, stem, and suffix divide up a path. The example uses /srv/holy/grail.tar.gz so that it also shows that stem removes only the final suffix.

The SVG places stem and suffix above the path and parent and name below it. Stem and suffix use blue and orange, with a half-character gap between their spans. The image uses the documentation theme's existing invert-in-dark-mode class, so it follows both the system preference and the manual theme selector.

The diagram has descriptive alt text giving all four values. HTML and EPUB both use the SVG. An explicit background preserves contrast in EPUB readers that override page colors without applying the documentation theme to images. Such readers retain a white diagram panel rather than placing dark text directly on a black page. The text remains SVG text, and the horizontal margins are balanced.

Validation:

  • Full HTML and EPUB builds passed with warnings treated as errors.
  • Chromium and Firefox checks passed for automatic light/dark mode and both manual overrides.
  • The stem/suffix gap remains visible in both browsers: 12 clear pixels at the image's 776-pixel width, and 4 at 320 pixels.
  • Verified that the EPUB archive references and contains the SVG, with the expected alt text.
  • All text colors exceed 5:1 against the image background in light mode and 8:1 after the dark-mode filter. Browser checks confirm the label colors exceed WCAG AA's 4.5:1 threshold.
  • Pre-commit checks passed for the changed files.

Books.app itself was not available for retesting.

Light mode:

Pathlib documentation in light mode, showing blue stem and orange suffix spans above the path and parent and name spans below it.

Dark mode:

The same pathlib documentation in dark mode, with brighter diagram colors on the page's dark background.

The diagram and documentation change were developed with AI assistance.

Comment thread Doc/library/pathlib-parts.png Outdated
@read-the-docs-community

read-the-docs-community Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35253400 | 📁 Comparing 7e26fb0 against main (415ebff)

  🔍 Preview build  

5 files changed · ± 5 modified

± Modified

Comment thread Doc/library/pathlib-parts.svg
@hugovk

hugovk commented Oct 19, 2026

Copy link
Copy Markdown
Member

I built an EPUB locally with make -C Doc epub && open Doc/build/epub/Python.epub and it looks like this in Books.app on macOS:

image image

Let's make the main path text more visible in dark mode. It looks like contrast ratio of the other text is a bit low as well, we should aim for the WCAG AA level of at least 4.5:1.

@pganssle

Copy link
Copy Markdown
Member Author

@hugovk I don't have Books.app, but I think it should be improved? Can you check it again?

@hugovk hugovk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HTML

image image

EPUB

image image

@pganssle
pganssle merged commit 4c356f7 into python:main Oct 20, 2026
34 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in Docs PRs Oct 20, 2026
@pganssle

Copy link
Copy Markdown
Member Author

Thanks for the reviews and feedback Hugo and Stan!

@hugovk hugovk added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Oct 20, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @pganssle for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Thanks @pganssle for the PR 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@bedevere-app

bedevere-app Bot commented Oct 20, 2026

Copy link
Copy Markdown

GH-159873 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Oct 20, 2026
@bedevere-app

bedevere-app Bot commented Oct 20, 2026

Copy link
Copy Markdown

GH-159874 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Oct 20, 2026
hugovk pushed a commit that referenced this pull request Oct 20, 2026
…59874)

Co-authored-by: Paul Ganssle <1377457+pganssle@users.noreply.github.com>
hugovk pushed a commit that referenced this pull request Oct 20, 2026
…59873)

Co-authored-by: Paul Ganssle <1377457+pganssle@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip issue skip news

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants