Skip to content

fix(filter): handle Python single-line docstrings in MinimalFilter#2713

Open
guyoron1 wants to merge 1 commit into
rtk-ai:developfrom
guyoron1:fix/filter-python-docstring-state
Open

fix(filter): handle Python single-line docstrings in MinimalFilter#2713
guyoron1 wants to merge 1 commit into
rtk-ai:developfrom
guyoron1:fix/filter-python-docstring-state

Conversation

@guyoron1

Copy link
Copy Markdown
Contributor

Summary

  • Fix MinimalFilter state corruption when encountering Python single-line docstrings like """Return the sum."""
  • The in_docstring flag was toggled to true but never reset when the closing """ appeared on the same line
  • All subsequent lines were treated as docstring content, preventing comment stripping and reducing token savings

Fix

After toggling in_docstring on, check if the rest of the line (after the opening """) contains a closing """:

if !in_docstring {
    in_docstring = true;
    if trimmed.len() > 3 && trimmed[3..].contains("\"\"\"") {
        in_docstring = false;
    }
} else {
    in_docstring = false;
}

Test plan

  • Added test_python_single_line_docstring_does_not_corrupt_state test
  • Verifies: docstring content kept, subsequent comment stripped, code preserved
  • cargo clippy --all-targets passes
  • cargo test --all passes

Fixes #2712

Single-line docstrings like """Return the sum.""" toggled in_docstring
to true but never back to false, causing all subsequent lines to be
treated as docstring content. Comments after such docstrings were not
stripped, reducing token savings.

Check for closing """ on the same line after opening to correctly
reset the state.

Fixes rtk-ai#2712
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.

Bug: Python single-line docstring corrupts MinimalFilter state — subsequent comments not stripped

1 participant