MCPcopy Index your code
hub / github.com/python/cpython / _line_pair_iterator

Function _line_pair_iterator

Lib/difflib.py:1547–1576  ·  view source on GitHub ↗

Yields from/to lines of text with a change indication. This function is an iterator. It itself pulls lines from the line iterator. Its difference from that iterator is that this function always yields a pair of from/to text lines (with the change indication). If n

()

Source from the content-addressed store, hash-verified

1545 yield from_line,to_line,True
1546
1547 def _line_pair_iterator():
1548 """Yields from/to lines of text with a change indication.
1549
1550 This function is an iterator. It itself pulls lines from the line
1551 iterator. Its difference from that iterator is that this function
1552 always yields a pair of from/to text lines (with the change
1553 indication). If necessary it will collect single from/to lines
1554 until it has a matching pair from/to pair to yield.
1555
1556 Note, this function is purposefully not defined at the module scope so
1557 that data it needs from its parent function (within whose context it
1558 is defined) does not need to be of module scope.
1559 """
1560 line_iterator = _line_iterator()
1561 fromlines,tolines=[],[]
1562 while True:
1563 # Collecting lines of text until we have a from/to pair
1564 while (len(fromlines)==0 or len(tolines)==0):
1565 try:
1566 from_line, to_line, found_diff = next(line_iterator)
1567 except StopIteration:
1568 return
1569 if from_line is not None:
1570 fromlines.append((from_line,found_diff))
1571 if to_line is not None:
1572 tolines.append((to_line,found_diff))
1573 # Once we have a pair, remove them from the collection and yield it
1574 from_line, fromDiff = fromlines.pop(0)
1575 to_line, to_diff = tolines.pop(0)
1576 yield (from_line,to_line,fromDiff or to_diff)
1577
1578 # Handle case where user does not want context differencing, just yield
1579 # them up without doing anything else with them.

Callers 1

_mdiffFunction · 0.85

Calls 3

_line_iteratorFunction · 0.85
appendMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…