Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

inspect.getsourcelines() is buggy on 3.12 #104866

Copy link
Copy link
Closed
@JelleZijlstra

Description

@JelleZijlstra
Issue body actions
% cat gsl.py
import inspect

def test_list_add(self):
    def capybara() -> None:
        assert_is_value(
            [x] + [y],
            z,
        )
        assert_is_value(
            # in the binop implementation
            a,
        )

print(inspect.getsourcelines(test_list_add))
% python3.11 gsl.py 
(['def test_list_add(self):\n', '    def capybara() -> None:\n', '        assert_is_value(\n', '            [x] + [y],\n', '            z,\n', '        )\n', '        assert_is_value(\n', '            # in the binop implementation\n', '            a,\n', '        )\n'], 3)
% ~/py/cpython/python.exe gsl.py 
(['def test_list_add(self):\n', '    def capybara() -> None:\n', '        assert_is_value(\n', '            [x] + [y],\n', '            z,\n', '        )\n', '        assert_is_value(\n', '            # in the binop implementation\n'], 3)
% ~/py/cpython/python.exe -V
Python 3.12.0b1+

On 3.12, the last two lines (a, )) are not returned as part of the source lines. When I tried to minify by removing the first assert_is_value() call, it instead returned the print() line as part of the function.

This looks related to the tokenizer, cc @pablogsal @lysnikolaou.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixesonly security fixes3.13bugs and security fixesbugs and security fixestype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.