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

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
@@ -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

@rchiodo
Copy link
Contributor Author

rchiodo commented Nov 4, 2024

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@rchiodo rchiodo merged commit 740fa9d into microsoft:main Nov 4, 2024
19 of 21 checks passed
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