MCPcopy
hub / github.com/psf/black / do_match

Method do_match

src/black/trans.py:425–472  ·  view source on GitHub ↗
(self, line: Line)

Source from the content-addressed store, hash-verified

423 """
424
425 def do_match(self, line: Line) -> TMatchResult:
426 LL = line.leaves
427
428 is_valid_index = is_valid_index_factory(LL)
429
430 string_indices = []
431 idx = 0
432 while is_valid_index(idx):
433 leaf = LL[idx]
434 if (
435 leaf.type == token.STRING
436 and is_valid_index(idx + 1)
437 and LL[idx + 1].type == token.STRING
438 ):
439 # Let's check if the string group contains an inline comment
440 # If we have a comment inline, we don't merge the strings
441 contains_comment = False
442 i = idx
443 while is_valid_index(i):
444 if LL[i].type != token.STRING:
445 break
446 if line.comments_after(LL[i]):
447 contains_comment = True
448 break
449 i += 1
450
451 if not contains_comment and not is_part_of_annotation(leaf):
452 string_indices.append(idx)
453
454 # Advance to the next non-STRING leaf.
455 idx += 2
456 while is_valid_index(idx) and LL[idx].type == token.STRING:
457 idx += 1
458
459 elif leaf.type == token.STRING and "\\\n" in leaf.value:
460 string_indices.append(idx)
461 # Advance to the next non-STRING leaf.
462 idx += 1
463 while is_valid_index(idx) and LL[idx].type == token.STRING:
464 idx += 1
465
466 else:
467 idx += 1
468
469 if string_indices:
470 return Ok(string_indices)
471 else:
472 return TErr("This line has no strings that need merging.")
473
474 def do_transform(
475 self, line: Line, string_indices: list[int]

Callers

nothing calls this directly

Calls 7

is_part_of_annotationFunction · 0.90
OkClass · 0.90
is_valid_index_factoryFunction · 0.85
is_valid_indexFunction · 0.85
TErrFunction · 0.85
comments_afterMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected