Return True if we have a magic trailing comma, that is when: - there's a trailing comma here - it's not from single-element square bracket indexing - it's not a one-tuple
(self, closing: Leaf)
| 334 | return any(is_multiline_string(leaf) for leaf in self.leaves) |
| 335 | |
| 336 | def has_magic_trailing_comma(self, closing: Leaf) -> bool: |
| 337 | """Return True if we have a magic trailing comma, that is when: |
| 338 | - there's a trailing comma here |
| 339 | - it's not from single-element square bracket indexing |
| 340 | - it's not a one-tuple |
| 341 | """ |
| 342 | if not ( |
| 343 | closing.type in CLOSING_BRACKETS |
| 344 | and self.leaves |
| 345 | and self.leaves[-1].type == token.COMMA |
| 346 | ): |
| 347 | return False |
| 348 | |
| 349 | if closing.type == token.RBRACE: |
| 350 | return True |
| 351 | |
| 352 | if closing.type == token.RSQB: |
| 353 | if ( |
| 354 | closing.parent is not None |
| 355 | and closing.parent.type == syms.trailer |
| 356 | and closing.opening_bracket is not None |
| 357 | and is_one_sequence_between( |
| 358 | closing.opening_bracket, |
| 359 | closing, |
| 360 | self.leaves, |
| 361 | brackets=(token.LSQB, token.RSQB), |
| 362 | ) |
| 363 | ): |
| 364 | assert closing.prev_sibling is not None |
| 365 | assert closing.prev_sibling.type == syms.subscriptlist |
| 366 | return False |
| 367 | |
| 368 | return True |
| 369 | |
| 370 | if self.is_import: |
| 371 | return True |
| 372 | |
| 373 | if closing.opening_bracket is not None and not is_one_sequence_between( |
| 374 | closing.opening_bracket, closing, self.leaves |
| 375 | ): |
| 376 | return True |
| 377 | |
| 378 | return False |
| 379 | |
| 380 | def append_comment(self, comment: Leaf) -> bool: |
| 381 | """Add an inline or standalone comment to the line.""" |
no test coverage detected