MCPcopy
hub / github.com/huggingface/transformers / find_block_end

Function find_block_end

utils/check_copies.py:260–285  ·  view source on GitHub ↗

Find the end of the class/func block starting at `start_index` in a source code (defined by `lines`). Args: lines (`List[str]`): The source code, represented by a list of lines. start_index (`int`): The starting index of the target class/func block.

(lines: list[str], start_index: int, indent: int)

Source from the content-addressed store, hash-verified

258
259
260def find_block_end(lines: list[str], start_index: int, indent: int) -> int:
261 """
262 Find the end of the class/func block starting at `start_index` in a source code (defined by `lines`).
263
264 Args:
265 lines (`List[str]`):
266 The source code, represented by a list of lines.
267 start_index (`int`):
268 The starting index of the target class/func block.
269 indent (`int`):
270 The indent of the class/func body.
271
272 Returns:
273 `int`: The index of the block's ending line plus by 1 (i.e. exclusive).
274 """
275 indent = " " * indent
276 # enter the block body
277 line_index = start_index + 1
278
279 while line_index < len(lines) and _should_continue(lines[line_index], indent):
280 line_index += 1
281 # Clean up empty lines at the end (if any).
282 while len(lines[line_index - 1]) <= 1:
283 line_index -= 1
284
285 return line_index
286
287
288def split_code_into_blocks(

Callers 2

split_code_into_blocksFunction · 0.85

Calls 1

_should_continueFunction · 0.85

Tested by

no test coverage detected