Skip to content

Add character-based string shortening with tests - #606

Closed
GitHubDalUser wants to merge 2 commits into
mahmoud:masterfrom
GitHubDalUser:assignment1-fix
Closed

GitHubDalUser wants to merge 2 commits into
mahmoud:masterfrom
GitHubDalUser:assignment1-fix

Conversation

@GitHubDalUser

@GitHubDalUser GitHubDalUser commented Oct 25, 2026 •

Copy link
Copy Markdown

The change

The backstory

AI assistance

  • Harness/tooling (Claude Code, Cursor, Codex, etc.):
  • Model(s):
  • Original prompt(s), as close to verbatim as you can manage:

Adds shorten_chars(text, width, placeholder='...') to boltons.strutils,
addressing #299. It truncates by character count and supports custom
placeholders while preserving strings that already fit.

Adds test_shorten_chars and test_shorten_chars_edge_cases, covering
truncation, unchanged inputs, None, empty strings, custom and empty
placeholders, small widths, and Unicode.

Validation on Windows with Python 3.12:

  • Before: 678 tests passed; wheel build succeeded.
  • After: 680 tests passed; wheel build succeeded.
  • The initial new test failed before implementation with ImportError.

Closes #299.

@mahmoud

mahmoud commented Oct 25, 2026

Copy link
Copy Markdown
Owner

strutils.ellipsize (added in 26.2.0) already covers shortening text with a placeholder, and a second character-only variant isn't something I want to add. Closing.

@mahmoud mahmoud closed this Oct 25, 2026
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.

Proposal: shorten long string by truncate chars (not by words)

2 participants