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):