Return a list of source lines and starting line number for an object. The argument may be a module, class, method, function, traceback, frame, or code object. The source code is returned as a list of the lines corresponding to the object and the line number indicates where in the o
(object)
| 1156 | return lines[:blockfinder.last] |
| 1157 | |
| 1158 | def getsourcelines(object): |
| 1159 | """Return a list of source lines and starting line number for an object. |
| 1160 | |
| 1161 | The argument may be a module, class, method, function, traceback, frame, |
| 1162 | or code object. The source code is returned as a list of the lines |
| 1163 | corresponding to the object and the line number indicates where in the |
| 1164 | original source file the first line of code was found. An OSError is |
| 1165 | raised if the source code cannot be retrieved.""" |
| 1166 | object = unwrap(object) |
| 1167 | lines, lnum = findsource(object) |
| 1168 | |
| 1169 | if istraceback(object): |
| 1170 | object = object.tb_frame |
| 1171 | |
| 1172 | # for module or frame that corresponds to module, return all source lines |
| 1173 | if (ismodule(object) or |
| 1174 | (isframe(object) and object.f_code.co_name == "<module>")): |
| 1175 | return lines, 0 |
| 1176 | else: |
| 1177 | return getblock(lines[lnum:]), lnum + 1 |
| 1178 | |
| 1179 | def getsource(object): |
| 1180 | """Return the text of the source code for an object. |
no test coverage detected
searching dependent graphs…