Extract the block of code at the top of the given list of lines.
(lines)
| 1137 | raise EndOfBlock |
| 1138 | |
| 1139 | def getblock(lines): |
| 1140 | """Extract the block of code at the top of the given list of lines.""" |
| 1141 | blockfinder = BlockFinder() |
| 1142 | try: |
| 1143 | tokens = tokenize.generate_tokens(iter(lines).__next__) |
| 1144 | for _token in tokens: |
| 1145 | blockfinder.tokeneater(*_token) |
| 1146 | except (EndOfBlock, IndentationError): |
| 1147 | pass |
| 1148 | except SyntaxError as e: |
| 1149 | if "unmatched" not in e.msg: |
| 1150 | raise e from None |
| 1151 | _, *_token_info = _token |
| 1152 | try: |
| 1153 | blockfinder.tokeneater(tokenize.NEWLINE, *_token_info) |
| 1154 | except (EndOfBlock, IndentationError): |
| 1155 | pass |
| 1156 | return lines[:blockfinder.last] |
| 1157 | |
| 1158 | def getsourcelines(object): |
| 1159 | """Return a list of source lines and starting line number for an object. |
no test coverage detected
searching dependent graphs…