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

Method enumerate_with_length

src/black/lines.py:448–467  ·  view source on GitHub ↗

Return an enumeration of leaves with their length. Stops prematurely on multiline strings and standalone comments.

(
        self, is_reversed: bool = False
    )

Source from the content-addressed store, hash-verified

446 )
447
448 def enumerate_with_length(
449 self, is_reversed: bool = False
450 ) -> Iterator[tuple[Index, Leaf, int]]:
451 """Return an enumeration of leaves with their length.
452
453 Stops prematurely on multiline strings and standalone comments.
454 """
455 op = cast(
456 Callable[[Sequence[Leaf]], Iterator[tuple[Index, Leaf]]],
457 enumerate_reversed if is_reversed else enumerate,
458 )
459 for index, leaf in op(self.leaves):
460 length = len(leaf.prefix) + len(leaf.value)
461 if "\n" in leaf.value:
462 return # Multiline strings, we can't continue.
463
464 for comment in self.comments_after(leaf):
465 length += len(comment.value)
466
467 yield index, leaf, length
468
469 def clone(self) -> "Line":
470 return Line(

Callers 3

_can_omit_opening_parenFunction · 0.80
_can_omit_closing_parenFunction · 0.80

Calls 1

comments_afterMethod · 0.95

Tested by

no test coverage detected