Raise :exc:`CannotSplit` if the last left- or right-hand split failed. Do nothing otherwise. A left- or right-hand split is based on a pair of brackets. Content before (and including) the opening bracket is left on one line, content inside the brackets is put on a separate line, an
(head: Line, body: Line, tail: Line)
| 1205 | |
| 1206 | |
| 1207 | def bracket_split_succeeded_or_raise(head: Line, body: Line, tail: Line) -> None: |
| 1208 | """Raise :exc:`CannotSplit` if the last left- or right-hand split failed. |
| 1209 | |
| 1210 | Do nothing otherwise. |
| 1211 | |
| 1212 | A left- or right-hand split is based on a pair of brackets. Content before |
| 1213 | (and including) the opening bracket is left on one line, content inside the |
| 1214 | brackets is put on a separate line, and finally content starting with and |
| 1215 | following the closing bracket is put on a separate line. |
| 1216 | |
| 1217 | Those are called `head`, `body`, and `tail`, respectively. If the split |
| 1218 | produced the same line (all content in `head`) or ended up with an empty `body` |
| 1219 | and the `tail` is just the closing bracket, then it's considered failed. |
| 1220 | """ |
| 1221 | tail_len = len(str(tail).strip()) |
| 1222 | if not body: |
| 1223 | if tail_len == 0: |
| 1224 | raise CannotSplit("Splitting brackets produced the same line") |
| 1225 | |
| 1226 | elif tail_len < 3: |
| 1227 | raise CannotSplit( |
| 1228 | f"Splitting brackets on an empty body to save {tail_len} characters is" |
| 1229 | " not worth it" |
| 1230 | ) |
| 1231 | |
| 1232 | |
| 1233 | def _ensure_trailing_comma( |
no test coverage detected