MCPcopy Index your code
hub / github.com/RustPython/RustPython / getblock

Function getblock

Lib/inspect.py:1115–1132  ·  view source on GitHub ↗

Extract the block of code at the top of the given list of lines.

(lines)

Source from the content-addressed store, hash-verified

1113 raise EndOfBlock
1114
1115def getblock(lines):
1116 """Extract the block of code at the top of the given list of lines."""
1117 blockfinder = BlockFinder()
1118 try:
1119 tokens = tokenize.generate_tokens(iter(lines).__next__)
1120 for _token in tokens:
1121 blockfinder.tokeneater(*_token)
1122 except (EndOfBlock, IndentationError):
1123 pass
1124 except SyntaxError as e:
1125 if "unmatched" not in e.msg:
1126 raise e from None
1127 _, *_token_info = _token
1128 try:
1129 blockfinder.tokeneater(tokenize.NEWLINE, *_token_info)
1130 except (EndOfBlock, IndentationError):
1131 pass
1132 return lines[:blockfinder.last]
1133
1134def getsourcelines(object):
1135 """Return a list of source lines and starting line number for an object.

Callers 1

getsourcelinesFunction · 0.85

Calls 3

tokeneaterMethod · 0.95
BlockFinderClass · 0.85
iterFunction · 0.85

Tested by

no test coverage detected