Skip to content

Adopt PEP 822 dedentation and default t-string alignment - #24

Merged
grahamcracker1234 merged 15 commits into
mainfrom
feat/pep-822-dedent
Aug 18, 2026
Merged

grahamcracker1234 merged 15 commits into
mainfrom
feat/pep-822-dedent

Conversation

@grahamcracker1234

@grahamcracker1234 grahamcracker1234 commented Aug 18, 2026 •

Copy link
Copy Markdown
Owner

Summary

Aligns dedent() with PEP 822 indentation and newline semantics while making multiline interpolation compose predictably across t-strings and f-strings.

Changes

  • Implements exact space/tab prefix matching, closing-line indentation controls, and errors for incompatible whitespace-only lines.
  • Aligns multiline t-string interpolations by default with per-value noalign, while supporting f-string alignment through align().
  • Refactors interpolation rendering into a single-pass literal-and-hole pipeline and preserves runtime line endings.
  • Splits tests by behavior, migrates snapshots to inline-snapshot, and updates development tooling.
  • Rewrites the README with a focused hero example, version-specific usage, a concise textwrap.dedent comparison, and PEP 822 reference material.

Note

High Risk
This is a breaking API and whitespace contract change across all dedent() callers, with a large refactor of core dedent/alignment logic and new error paths for malformed indentation.

Overview
dedent() now follows PEP 822 indentation: exact space/tab prefixes, closing-line control of trailing newlines, and IndentationError on incompatible whitespace-only lines. It drops the opening newline after triple quotes and removes the strip and align keyword arguments—other whitespace is left intact.

Interpolation is reworked so literal segments are dedented before holes are filled. t-strings align multiline values by default; {value:noalign} opts out. align() remains for f-strings and TypeError if used in t-strings.

The README is rewritten around the new behavior and rules. Tests move to inline-snapshot and split by concern; dev tooling (ruff, basedpyright, etc.) is bumped.

Reviewed by Cursor Bugbot for commit f57c91d. Bugbot is set up for automated code reviews on this repo. Configure here.

Use exact indentation-prefix semantics while preserving interpolation support and documenting runtime differences.
Preserve exact line-ending and indentation semantics while rendering template and alignment holes without letting interpolated values alter dedentation.
Keep continuation lines directly beneath each interpolation, including nested and same-line values, so rendered output remains structurally aligned.
Adopt current lint rule names and refresh test, type-checking, formatting, and lockfile dependencies.
Remove the strip modes so dedent omits only the opening newline and preserves all remaining whitespace, matching PEP 822 quote-placement semantics.
Remove redundant global and opt-in controls so only explicit per-value noalign exceptions remain.
Repository owner deleted a comment from cursor Bot Aug 18, 2026
@grahamcracker1234 grahamcracker1234 changed the title Align dedent behavior with PEP 822 Adopt PEP 822 dedentation and default t-string alignment Aug 18, 2026
Fail clearly when the f-string-only wrapper reaches a t-string, avoiding ambiguous alignment precedence.
Treat spaces and tabs before the first line ending as the opener while documenting runtime divergences from PEP 822.
Protect conversion handling and column tracking across consecutive multiline values.
Keep literal parts structural so dedentation no longer requires UUID markers or regex reconstruction.
Repository owner deleted a comment from cursor Bot Aug 18, 2026
@grahamcracker1234

Copy link
Copy Markdown
Owner Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit f57c91d. Configure here.

@grahamcracker1234
grahamcracker1234 merged commit a913c73 into main Aug 18, 2026
5 checks passed
@grahamcracker1234
grahamcracker1234 deleted the feat/pep-822-dedent branch August 18, 2026 18:42
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.

Implement PEP 822 dedentation semantics Enable align by default

1 participant