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): diff --git a/pudb/test/test_lowlevel.py b/pudb/test/test_lowlevel.py index b5131c64..da7b5bd8 100644 --- a/pudb/test/test_lowlevel.py +++ b/pudb/test/test_lowlevel.py @@ -89,10 +89,13 @@ def main(): test_code = "a = 3*5\n" + 333 * "\n" + "b = 15" expected = { 1, - 128, # bogus, - 255, # bogus, 335 } + if sys.version_info < (3, 12): + expected.update([ + 128, # bogus, + 255, # bogus, + ]) if sys.version_info >= (3, 11): # See https://github.com/python/cpython/pull/94562 and # https://peps.python.org/pep-0626/