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)
| 1132 | return lines[:blockfinder.last] |
| 1133 | |
| 1134 | def getsourcelines(object): |
| 1135 | """Return a list of source lines and starting line number for an object. |
| 1136 | |
| 1137 | The argument may be a module, class, method, function, traceback, frame, |
| 1138 | or code object. The source code is returned as a list of the lines |
| 1139 | corresponding to the object and the line number indicates where in the |
| 1140 | original source file the first line of code was found. An OSError is |
| 1141 | raised if the source code cannot be retrieved.""" |
| 1142 | object = unwrap(object) |
| 1143 | lines, lnum = findsource(object) |
| 1144 | |
| 1145 | if istraceback(object): |
| 1146 | object = object.tb_frame |
| 1147 | |
| 1148 | # for module or frame that corresponds to module, return all source lines |
| 1149 | if (ismodule(object) or |
| 1150 | (isframe(object) and object.f_code.co_name == "<module>")): |
| 1151 | return lines, 0 |
| 1152 | else: |
| 1153 | return getblock(lines[lnum:]), lnum + 1 |
| 1154 | |
| 1155 | def getsource(object): |
| 1156 | """Return the text of the source code for an object. |
no test coverage detected