Skip to content

libs/textwrap/no_line_continuations#11

Open
thatch wants to merge 1 commit intomainfrom
thatch/textwrap-line-continuations
Open

libs/textwrap/no_line_continuations#11
thatch wants to merge 1 commit intomainfrom
thatch/textwrap-line-continuations

Conversation

@thatch
Copy link
Copy Markdown
Member

@thatch thatch commented Mar 25, 2026

Finds cases like

textwrap.dedent("""
x \
y
""")

which can't be safely reindented without changing their final value.

Finds cases like

    textwrap.dedent("""
    x \
    y
    """)

which can't be safely reindented without changing their final value.
@thatch thatch requested a review from nedbat March 25, 2026 23:17
@nedbat
Copy link
Copy Markdown
Collaborator

nedbat commented Mar 26, 2026

I'm not sure what's going on, but when I try to apply this to coverage, it says NEEDS_WORK, but --patch doesn't show a patch and --apply makes no changes:

% git checkout 6bb59f4efa80a4b30ddbe8d958bf1748421dc0c7
HEAD is now at 6bb59f4e chore: bump actions/download-artifact in the action-dependencies group (#2147)

% ick --rules-repo=https://github.com/codrsquad/rulez@thatch/textwrap-line-continuations run libs/textwrap/no_line_continuations
Running...  [------------------------------------]    0%

-> libs/textwrap/no_line_continuations: NEEDS_WORK
     tests/test_phystokens.py:114: line-continuation backslash in textwrap.dedent string


% ick --rules-repo=https://github.com/codrsquad/rulez@thatch/textwrap-line-continuations run libs/textwrap/no_line_continuations --patch
Running...  [------------------------------------]    0%

-> libs/textwrap/no_line_continuations: NEEDS_WORK
     tests/test_phystokens.py:114: line-continuation backslash in textwrap.dedent string


% ick --rules-repo=https://github.com/codrsquad/rulez@thatch/textwrap-line-continuations run libs/textwrap/no_line_continuations --apply
Running...  [------------------------------------]    0%

-> libs/textwrap/no_line_continuations: NEEDS_WORK
     tests/test_phystokens.py:114: line-continuation backslash in textwrap.dedent string


% git status
HEAD detached at 6bb59f4e
nothing to commit, working tree clean

% bat -r 110:120 tests/test_phystokens.py
  ─────┬──────────────────────
   110 │     def test_1828(self) -> None:
   111 │         # https://github.com/coveragepy/coveragepy/pull/1828
   112 │         tokens = list(
   113 │             source_token_lines(
   114 │                 textwrap.dedent("""
   115 │             x = \
   116 │                 1
   117 │             a = ["aaa",\\
   118 │                  "bbb \\
   119 │                  ccc"]
   120 │             """)
  ─────┴───────────────────────

@thatch
Copy link
Copy Markdown
Member Author

thatch commented Mar 26, 2026

That's expected, it prints a message and exits 99 on affected files. I couldn't figure out an autofix I was happy with -- getting rid of the continuation but keeping the same (weird) value didn't seem good, and doubling the backslash to do what the user probably intended isn't really better because it will probably break behavior you were relying on.

@nedbat
Copy link
Copy Markdown
Collaborator

nedbat commented Mar 27, 2026

Maybe we should have ick print a message then: "No fix available"

@thatch
Copy link
Copy Markdown
Member Author

thatch commented Mar 27, 2026

NEEDS_WORK is supposed to include both "no autofix" and "incomplete autofix" -- as an example, we might have one batch exit 0 and one batch exit 99 -- "human, take a look" is what you need to do because it's not fully automatic. Fingers crossed this is just a wordsmithing problem?

We could potentially add another status that's just "unsafe fix" if that's more user-friendly to retry with another flag.

@nedbat
Copy link
Copy Markdown
Collaborator

nedbat commented Mar 27, 2026

Maybe instead of status codes we should piggyback on structured metadata. It would definitely help to clearly indicate that the rules wants a change but cannot make the change.

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