Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In 3.12 findlinestarts seems to return None for line more often #1721

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def iterate():
# bodies of nested class and function definitions, as they have their
# own objects.
for _, lineno in dis.findlinestarts(code):
yield lineno
if lineno is not None:
yield lineno

# For nested class and function definitions, their respective code objects
# are constants referenced by this object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def _get_code_line_info(code_obj):
last_line = None

for offset, line in dis.findlinestarts(code_obj):
line_to_offset[line] = offset
if line is not None and offset is not None:
line_to_offset[line] = offset

if line_to_offset:
first_line = min(line_to_offset)
Expand Down
4 changes: 2 additions & 2 deletions src/debugpy/_vendored/pydevd/pydevd.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,10 +791,10 @@ def collect_try_except_info(self, code_obj):
max_line = -1
min_line = sys.maxsize
for _, line in dis.findlinestarts(code_obj):
if line > max_line:
if line is not None and line > max_line:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused about how line can be None since dis.findlinestarts checks for None before yielding.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what makes you say that? The docs at least say it can be none. dis.findlinestarts is supposed to call: https://docs.python.org/3/reference/datamodel.html#codeobject.co_lines.

I didn't check the source in CPython though

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't notice that it wasn't our code. I just used "go to def"` and saw this. Turns out this is from my CPython 3.12.7 install.

def findlinestarts(code):
    """Find the offsets in a byte code which are start of lines in the source.

    Generate pairs (offset, lineno)
    """
    lastline = None
    for start, end, line in code.co_lines():
        if line is not None and line != lastline:
            lastline = line
            yield start, line
    return

max_line = line

if line < min_line:
if line is not None and line < min_line:
min_line = line

try_except_infos = [x for x in try_except_infos if min_line <= x.try_line <= max_line]
Expand Down
Loading