Skip to content

Pad standalone type chips, keep compound types flush#54

Merged
tony merged 2 commits into
mainfrom
typehints-chip-padding
Jun 7, 2026
Merged

Pad standalone type chips, keep compound types flush#54
tony merged 2 commits into
mainfrom
typehints-chip-padding

Conversation

@tony

@tony tony commented Jun 7, 2026

Copy link
Copy Markdown
Member

Summary

  • Fix field-list type chips (str, pathlib.Path, union members) rendering with zero horizontal padding — each type sat crammed against the edge of its chip background.
  • Restore Furo's 0.2em inline padding on .field-list code.literal, which sphinx-autodoc-typehints-gp had zeroed globally.
  • Preserve the tight compound rendering (list[str], dict[str, Any]) by cancelling that padding only where a chip abuts .p punctuation.

Background

typehints_gp.css zeroed padding-inline on every field-list code chip so compound annotations stayed flush — list[str], not list[ str ], since the brackets/commas live in separate <span class="p"> elements outside the chip. The side effect: standalone types (a parameter that is just str, a return of pathlib.Path) lost their chip breathing room and read as text jammed against the background edge. The earlier api-facts padding fix only covered .gp-sphinx-api-facts, so plain autodoc parameter lists on consumer sites (libtmux, django-docutils, …) kept the cramped look.

The fix

Restore the padding by default, then drop it adjacently to punctuation:

.field-list code.literal { padding-inline: 0.2em; }
.field-list code.literal:has(+ .p),
.field-list a.reference:has(+ .p) > code.literal { padding-inline-end: 0; }
.field-list .p + code.literal,
.field-list .p + a.reference > code.literal { padding-inline-start: 0; }

Linked chips wrap the <code> in <a>, so the punctuation is the anchor's sibling — the rule matches both the bare and anchored forms. Browsers without :has() degrade gracefully to padded-everywhere.

Before / After

Chip Context Before After
str standalone flush to edges 0.2em breathing room
pathlib.Path standalone flush to edges 0.2em breathing room
Callable before [ flush flush (unchanged)
Server inside […] flush flush (unchanged)

Verified live: dict[str, Any] | None keeps dict[str, Any] tight while the | None members gain padding.

Test plan

  • uv run ruff check . / ruff format / uv run mypy . clean
  • uv run pytest --reruns 0 — full suite green
  • just build-docs succeeds; the rule is bundled into _static/css/typehints_gp.css
  • Prototyped live on a production consumer page; standalone chips padded, list[str]/dict[str, Any] stay flush

…rackets

why: Field-list type chips — standalone types like str and pathlib.Path
and union members — rendered with zero horizontal padding, so each type
sat crammed against the edge of its chip background. The padding was
zeroed globally to keep compound types tight (list[str], not
list[ str ]).

what:
- Restore Furo's 0.2em inline padding on .field-list code.literal
- Cancel it only where a chip abuts .p punctuation (brackets, inner
  commas, pipes), matching both the bare <code> and the <a>-wrapped
  link form, so list[str] and dict[str, Any] still render flush
@codecov-commenter

codecov-commenter commented Jun 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.38%. Comparing base (12483f3) to head (d0abf80).

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #54   +/-   ##
=======================================
  Coverage   92.38%   92.38%           
=======================================
  Files         256      256           
  Lines       20188    20188           
=======================================
  Hits        18651    18651           
  Misses       1537     1537           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tony tony merged commit 628a9e2 into main Jun 7, 2026
44 checks passed
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.

2 participants