def getblock(lines):
"""Extract the block of code at the top of the given list of lines."""
blockfinder = inspect.BlockFinder()
try:
tokens = inspect.tokenize.generate_tokens(iter(lines).__next__)
for _token in tokens:
blockfinder.tokeneater(*_token)
except (inspect.EndOfBlock, IndentationError):
pass
return lines # different to builtin inspect is here
评论列表
文章目录