Skip to content

Skip lines emptied by whitespace stripping in wrap - #291

Closed
deepanshupal wants to merge 2 commits into
jquast:masterfrom
deepanshupal:fix/wrap-leading-blank-line
Closed

deepanshupal wants to merge 2 commits into
jquast:masterfrom
deepanshupal:fix/wrap-leading-blank-line

Conversation

@deepanshupal

Copy link
Copy Markdown
Contributor

After stripping trailing whitespace, do not append a line that has become empty. Keep the first-line state unchanged so initial indentation still belongs to the first line with content.

Add three regressions for one, two, and four leading spaces before a long word at width 1. Also check that drop_whitespace=False still preserves those spaces.

This closes a remaining edge case of #170, rather than changing the documented whitespace behavior.

Validation on Python 3.10.12/Linux:

  • Before the source fix: all three new cases fail with an unwanted empty first line.
  • Pure-Python full suite and doctests: 1703 passed, 49 skipped.
  • C-extension full suite and doctests: 1739 passed, 13 skipped.
  • mypy --strict wcwidth: no issues in 49 source files.
  • Changed-file Flake8 and pydocstyle clean; Pylint on textwrap.py rated 10/10.

Other Python versions, platforms, docs builds, and the standalone C-library suite were not run. No C code changed; wrapping uses the Python implementation in both modes.

@codspeed

codspeed Bot commented Oct 4, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 121 untouched benchmarks


Comparing DeepanshuPal:fix/wrap-leading-blank-line (70b4c92) with master (b770e71)

Open in CodSpeed

@codecov

codecov Bot commented Oct 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.61%. Comparing base (b770e71) to head (70b4c92).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #291   +/-   ##
=======================================
  Coverage   87.61%   87.61%           
=======================================
  Files          41       41           
  Lines        5611     5613    +2     
  Branches     1502     1503    +1     
=======================================
+ Hits         4916     4918    +2     
  Misses        321      321           
  Partials      374      374           

☔ 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.

jquast added a commit that referenced this pull request Oct 4, 2026
Bugfix `wrap()` should omit an empty line as output, like `textwrap.wrap()` does

This is PR #291 with matching libwcwidth change and tests.

---------

Co-authored-by: Deepanshu Pal <[email protected]>
@jquast

jquast commented Oct 4, 2026

Copy link
Copy Markdown
Owner

merged

@jquast jquast closed this Oct 4, 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.

2 participants