Try to find the first executable line of the code object. Equivalently, find the line number of the instruction that's after RESUME Return code.co_firstlineno if no executable line is found.
(code)
| 117 | |
| 118 | |
| 119 | def find_first_executable_line(code): |
| 120 | """ Try to find the first executable line of the code object. |
| 121 | |
| 122 | Equivalently, find the line number of the instruction that's |
| 123 | after RESUME |
| 124 | |
| 125 | Return code.co_firstlineno if no executable line is found. |
| 126 | """ |
| 127 | prev = None |
| 128 | for instr in dis.get_instructions(code): |
| 129 | if prev is not None and prev.opname == 'RESUME': |
| 130 | if instr.positions.lineno is not None: |
| 131 | return instr.positions.lineno |
| 132 | return code.co_firstlineno |
| 133 | prev = instr |
| 134 | return code.co_firstlineno |
| 135 | |
| 136 | def find_function(funcname, filename): |
| 137 | cre = re.compile(r'(?:async\s+)?def\s+%s(\s*\[.+\])?\s*[(]' % re.escape(funcname)) |
no test coverage detected
searching dependent graphs…