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
(object)
| 1229 | return lines[:blockfinder.last] |
| 1230 | |
| 1231 | def getsourcelines(object): |
| 1232 | """Return a list of source lines and starting line number for an object. |
| 1233 | |
| 1234 | The argument may be a module, class, method, function, traceback, frame, |
| 1235 | or code object. The source code is returned as a list of the lines |
| 1236 | corresponding to the object and the line number indicates where in the |
| 1237 | original source file the first line of code was found. An OSError is |
| 1238 | raised if the source code cannot be retrieved.""" |
| 1239 | object = unwrap(object) |
| 1240 | lines, lnum = findsource(object) |
| 1241 | |
| 1242 | if istraceback(object): |
| 1243 | object = object.tb_frame |
| 1244 | |
| 1245 | # for module or frame that corresponds to module, return all source lines |
| 1246 | if (ismodule(object) or |
| 1247 | (isframe(object) and object.f_code.co_name == "<module>")): |
| 1248 | return lines, 0 |
| 1249 | else: |
| 1250 | return getblock(lines[lnum:]), lnum + 1 |
| 1251 | |
| 1252 | def getsource(object): |
| 1253 | """Return the text of the source code for an object. |
no test coverage detected