Returns: string_idx such that @line.leaves[string_idx] is equal to our target (i.e. matched) string, if the line is a bare trailing comma tuple (STRING + COMMA) not inside brackets. OR None, otherwise. This handles the
(line: Line)
| 2200 | |
| 2201 | @staticmethod |
| 2202 | def _trailing_comma_tuple_match(line: Line) -> int | None: |
| 2203 | """ |
| 2204 | Returns: |
| 2205 | string_idx such that @line.leaves[string_idx] is equal to our target |
| 2206 | (i.e. matched) string, if the line is a bare trailing comma tuple |
| 2207 | (STRING + COMMA) not inside brackets. |
| 2208 | OR |
| 2209 | None, otherwise. |
| 2210 | |
| 2211 | This handles the case from issue #4912 where a long string with a |
| 2212 | trailing comma (making it a one-item tuple) needs to be wrapped in |
| 2213 | parentheses before splitting to preserve AST equivalence. |
| 2214 | """ |
| 2215 | LL = line.leaves |
| 2216 | # Match: STRING followed by COMMA, not inside brackets |
| 2217 | if ( |
| 2218 | not line.inside_brackets |
| 2219 | and len(LL) == 2 |
| 2220 | and LL[0].type == token.STRING |
| 2221 | and LL[1].type == token.COMMA |
| 2222 | ): |
| 2223 | return 0 |
| 2224 | |
| 2225 | return None |
| 2226 | |
| 2227 | def do_transform( |
| 2228 | self, line: Line, string_indices: list[int] |