Skip to content

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

Merged
rchiodo merged 1 commit intomicrosoft:mainfrom
rchiodo:rchiodo/fix_findlinestarts
Nov 4, 2024
Merged

In 3.12 findlinestarts seems to return None for line more often#1721
rchiodo merged 1 commit intomicrosoft:mainfrom
rchiodo:rchiodo/fix_findlinestarts

Conversation

@rchiodo
Copy link
Contributor

@rchiodo rchiodo commented Nov 4, 2024

Fixes #1720

@rchiodo rchiodo requested a review from a team as a code owner November 4, 2024 17:47
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

@rchiodo
Copy link
Contributor Author

rchiodo commented Nov 4, 2024

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@rchiodo rchiodo merged commit 740fa9d into microsoft:main Nov 4, 2024
rchiodo added a commit to rchiodo/debugpy that referenced this pull request Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError: 'None' comparison in collect_try_except_info()

2 participants