From 58667e097f71f4390952a8b47c3ef1e37d8de43d Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 4 Dec 2023 11:47:41 -0600 Subject: [PATCH] Use co_lines to find executable lines if available --- pudb/lowlevel.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/pudb/lowlevel.py b/pudb/lowlevel.py index 8b1eafa4..f13886f6 100644 --- a/pudb/lowlevel.py +++ b/pudb/lowlevel.py @@ -24,6 +24,7 @@ """ +import sys import logging from datetime import datetime @@ -94,17 +95,22 @@ def _init_loggers(): # {{{ breakpoint validity def generate_executable_lines_for_code(code): - lineno = code.co_firstlineno - yield lineno - # See https://github.com/python/cpython/blob/master/Objects/lnotab_notes.txt - - for line_incr in code.co_lnotab[1::2]: - # NB: This code is specific to Python 3.6 and higher - # https://github.com/python/cpython/blob/v3.6.0/Objects/lnotab_notes.txt - if line_incr >= 0x80: - line_incr -= 0x100 - lineno += line_incr + if sys.version_info >= (3, 10): + for _start, _end, lineno in code.co_lines(): + if lineno is not None: + yield lineno + else: + lineno = code.co_firstlineno yield lineno + # See https://github.com/python/cpython/blob/master/Objects/lnotab_notes.txt + + for line_incr in code.co_lnotab[1::2]: + # NB: This code is specific to Python 3.6 and higher + # https://github.com/python/cpython/blob/v3.6.0/Objects/lnotab_notes.txt + if line_incr >= 0x80: + line_incr -= 0x100 + lineno += line_incr + yield lineno def get_executable_lines_for_codes_recursive(codes):