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

Method add_backslash_continuation

Lib/tokenize.py:185–200  ·  view source on GitHub ↗

Add backslash continuation characters if the row has increased without encountering a newline token. This also inserts the correct amount of whitespace before the backslash.

(self, start)

Source from the content-addressed store, hash-verified

183 self.tokens.append(" " * col_offset)
184
185 def add_backslash_continuation(self, start):
186 """Add backslash continuation characters if the row has increased
187 without encountering a newline token.
188
189 This also inserts the correct amount of whitespace before the backslash.
190 """
191 row = start[0]
192 row_offset = row - self.prev_row
193 if row_offset == 0:
194 return
195
196 newline = '\r\n' if self.prev_line.endswith('\r\n') else '\n'
197 line = self.prev_line.rstrip('\\\r\n')
198 ws = ''.join(_itertools.takewhile(str.isspace, reversed(line)))
199 self.tokens.append(ws + f"\\{newline}" * row_offset)
200 self.prev_col = 0
201
202 def escape_brackets(self, token):
203 characters = []

Callers 1

add_whitespaceMethod · 0.95

Calls 4

endswithMethod · 0.45
rstripMethod · 0.45
joinMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected