Repository navigation
Conversation
📊 Automated PR Analysis
SummaryFixes MinimalFilter incorrectly entering docstring mode when a Python docstring opens and closes on the same line, which caused subsequent comments to remain unstripped. Adds regression tests covering single-line, empty, Unicode, and multiline docstring cases. Review Checklist
Analyzed automatically by wshm · This is an automated analysis, not a human review. |
Protocol-zero-0
left a comment
There was a problem hiding this comment.
Tested this locally: the new single-line and multiline docstring tests pass (I ran them on this branch merged with #4205, see below).
One interaction worth knowing before it lands. Today, a one-line docstring leaves the filter stuck "inside a docstring" for the rest of the file (#1322), and that stuck state happens to hide a separate bug: a line like s = """ is treated as a one-line block comment and deleted (finding 2 of #3425). With this fix alone, the stuck state goes away and that deletion starts showing up after every one-line docstring:
def f():
"""One-line docstring."""
# strip me
s = """
multi
"""
return s$ rtk read d.py -l minimal # this branch
def f():
"""One-line docstring."""
multi
"""
return s
s = """ is gone, so multi reads as code and the lone """ opens a string.
I've opened #4205 for the underlying block-comment detection (#3425). It doesn't touch the branch this PR changes, the two merge cleanly, and with both applied the output is right: docstring kept, # strip me removed, s = """ kept. So there's nothing to change here; landing #4205 before or alongside this one avoids the window where the bug is more visible.
|
@KuSh Could you please review it? Thanks! |
Round 1 of 3 — DUPLICATE, closing in favour of #3336Claim: stop a one-line Python docstring ( Thanks for the fix and the tests. The stuck state is real, and this change clears it: your repro strips both The interaction @Protocol-zero-0 described is wider than the
Per file, develop → this PR: 153 files that were intact on develop now lose code, and 283 lose more than before (+1,260 lines). The worst is #3336 handles the one-line docstring and the |
Summary
Fixes #1322.
MinimalFilterenters docstring mode when a Python docstring opens and closes on the same line, causing subsequent comments to remain in the output.Only toggle the state when entering or leaving a multiline docstring. This keeps single-line docstrings intact while allowing subsequent comments to be stripped.
Adds regression coverage for single-line, empty, Unicode, and multiline docstrings, including a single-line docstring with a trailing comment.
Test plan
cargo fmt --all --check && cargo clippy --all-targets --locked && cargo test --locked: 3,922 passed, 8 ignored.rtk read sample.py --level minimalremoves subsequent comments while preserving the docstring;--level nonepreserves the original file.