Skip to content

Commit

Permalink
0.12.2! Minor lines_strip_indent semantic change.
Browse files Browse the repository at this point in the history
A minor semantic change to lines_strip_indent: when it encounters
a whitespace-only line, it clips the line to *trailing* in the
LineInfo object.  It used to clip such lines to *leading*.  But this
changed LineInfo.column_number in a nonsensical way.

This behavior is policy going forward: if a lines modifer function
ever clips the entire line, it must clip it to *trailing* rather than
*leading*.  It shouldn't matter one way or another, as whitespace-only
lines arguably shouldn't have any explicit semantics.  But it makes
intuitive sense to me that their empty line should be at column number 1,
rather than 9 or 13 or whatnot.  (Especially considering that with
lines_strip_indent their indent value is synthetic anyway,
inferred by looking ahead.)

Also, a major cleanup to the lines modifier test suites.
  • Loading branch information
larryhastings committed Sep 12, 2024
1 parent 482ee60 commit 1f08242
Show file tree
Hide file tree
Showing 4 changed files with 357 additions and 397 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6134,6 +6134,29 @@ in the **big** test suite.

## Release history

#### 0.12.2

*2024/09/11*

<dl><dd>

* A minor semantic change to [`lines_strip_indent`](#lines_strip_indentli):
when it encounters a whitespace-only line, it clips the line to *trailing*
in the `LineInfo` object. It used to clip such lines to *leading*. But this
changed `LineInfo.column_number` in a nonsensical way.

This behavior is policy going forward: if a lines modifer function ever clips
the entire line, it must clip it to *trailing* rather than *leading*. It
shouldn't matter one way or another, as whitespace-only lines arguably
shouldn't have any explicit semantics. But it makes intuitive sense to me
that their empty line should be at column number 1, rather than 9 or 13
or whatnot. (Especially considering that with `lines_strip_indent` their
indent value is synthetic anyway, inferred by looking ahead.)

* Major cleanup to the lines modifier test suites.

</dd></dl>

#### 0.12.1

*2024/09/07*
Expand Down
2 changes: 1 addition & 1 deletion big/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""

__version__ = "0.12.1"
__version__ = "0.12.2"
10 changes: 9 additions & 1 deletion big/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -3404,7 +3404,11 @@ def lines_strip_indent(li):

lstripped = line.lstrip()
if not lstripped:
line = info.clip_leading(line, line)
# yes, clip *TRAILING*.
# When a line is 100% whitespace,
# always clip to trailing.
# That way you don't change column_number nonsensically.
line = info.clip_trailing(line, line)
blank_lines.append((info, line))
# print(f"BL+ {info=} {lstripped=}")
continue
Expand Down Expand Up @@ -3480,6 +3484,10 @@ def lines_filter_empty_lines(li):
(line_number=3, "a")
(line_number=5, "b")
Doesn't strip whitespace (or anything else). If you want to filter
out lines that only contain whitespace, add lines_rstrip to the chain
of lines modifiers before lines_filter_empty_lines.
Composable with all the lines_ modifier functions in the big.text module.
"""
for t in li:
Expand Down
Loading

0 comments on commit 1f08242

Please sign in to comment.