True when the sanitized line ends with a continuation operator. `is_inner` distinguishes the first physical line of a logical property (where a trailing `:` is the prop separator) from absorbed continuation lines (where `:` usually means ternary middle). An extra guard handles tern
(line: str, is_inner: bool)
| 229 | |
| 230 | |
| 231 | def _has_trailing_operator(line: str, is_inner: bool) -> bool: |
| 232 | """True when the sanitized line ends with a continuation operator. |
| 233 | |
| 234 | `is_inner` distinguishes the first physical line of a logical property |
| 235 | (where a trailing `:` is the prop separator) from absorbed continuation |
| 236 | lines (where `:` usually means ternary middle). |
| 237 | |
| 238 | An extra guard handles ternary-middle on the FIRST line too: |
| 239 | `icon.source: checked ? "a" :` has a trailing `:` that is not the prop |
| 240 | separator (the prop-separator `:` comes after `icon.source` and is |
| 241 | followed by a non-empty value). We detect this by counting unbalanced |
| 242 | `?`: if the sanitized text has more `?` than `:` after the prop |
| 243 | separator, a trailing `:` must be completing a ternary and we absorb. |
| 244 | """ |
| 245 | sanitized = _strip_strings_and_comments(line).rstrip() |
| 246 | if not sanitized: |
| 247 | return False |
| 248 | |
| 249 | pattern = _TRAILING_OPERATOR_INNER if is_inner else _TRAILING_OPERATOR_FIRST |
| 250 | if pattern.search(sanitized): |
| 251 | return True |
| 252 | |
| 253 | # First-line ternary-middle: `prop: ... ? ... :` |
| 254 | if not is_inner and sanitized.endswith(":"): |
| 255 | # Strip the property-separator `:` and whatever precedes it, then |
| 256 | # check the remaining value text for unbalanced `?`. The trailing |
| 257 | # `:` is the operator we're evaluating, so drop it before counting. |
| 258 | m = re.match( |
| 259 | r"\s*(?:readonly\s+)?(?:property\s+\w+\s+)?[A-Za-z_][\w.]*\s*:(.*)$", |
| 260 | sanitized, |
| 261 | ) |
| 262 | if m: |
| 263 | value = m.group(1).rstrip() |
| 264 | if value.endswith(":"): |
| 265 | value = value[:-1] |
| 266 | q = value.count("?") |
| 267 | c = value.count(":") |
| 268 | if q > c: |
| 269 | return True |
| 270 | |
| 271 | return False |
| 272 | |
| 273 | |
| 274 | @dataclass |
no test coverage detected