GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Incorrect line number calculated in traceback · Issue #93662 · python/cpython

Incorrect line number calculated in traceback #93662

New issue
Copy link
New issue
Copy link
Closed
Closed
Incorrect line number calculated in traceback#93662
Copy link
Assignees
markshannon
Labels
3.11only security fixesonly security fixesrelease-blocker

Description

@pablogsal
pablogsal
opened on Jun 9, 2022
Issue body actions

Consider the following code:

def _run_with_file_output():
    example_report_generation_message= (
            """
            """
    ).strip()
    raise ValueError()

_run_with_file_output()

If you execute this with 3.11.0a7 you get (correct traceback):

Traceback (most recent call last):
  File "/home/pablogsal/github/python/3.11/lel.py", line 8, in <module>
    _run_with_file_output()
    ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pablogsal/github/python/3.11/lel.py", line 6, in _run_with_file_output
    raise ValueError()
    ^^^^^^^^^^^^^^^^^^
ValueError

but on 3.11.0b1 you get:

Traceback (most recent call last):
  File "/home/pablogsal/github/python/3.11/lel.py", line 8, in <module>
    _run_with_file_output()
    ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pablogsal/github/python/3.11/lel.py", line 255, in _run_with_file_output
ValueError

Notice that the last line number for _run_with_file_output is wrong (255 instead of 6).

Bisecting points at:

944fffee8916cb94321fa33cd3a43f4108717746 is the first bad commit
commit 944fffee8916cb94321fa33cd3a43f4108717746
Author: Mark Shannon <[email protected]>
Date:   Thu Apr 21 16:10:37 2022 +0100

    GH-88116: Use a compact format to represent end line and column offsets. (GH-91666)

    * Stores all location info in linetable to conform to PEP 626.

    * Remove column table from code objects.

    * Remove end-line table from code objects.

    * Document new location table format

Activity

  1. pablogsal
    added
    release-blocker
    3.11only security fixesonly security fixes
    on Jun 9, 2022
  2. pablogsal
    assigned
    markshannon
    on Jun 9, 2022
  3. pablogsal commented on Jun 9, 2022

    @pablogsal
    pablogsal
    on Jun 9, 2022
    MemberAuthor
    More actions

    Originally noticed by @godlygeek

    Reacted by Matt Wozniski
  4. pablogsal commented on Jun 9, 2022

    @pablogsal
    pablogsal
    on Jun 9, 2022
    MemberAuthor
    More actions

    Notice that if you change the input to be:

    def _run_with_file_output():
        _= (
                """
                """
        ).strip()
        raise ValueError()
    
    _run_with_file_output()
    

    Then the line numbers and the tracebacks are correct (likely due to the difference in column offset):

    Traceback (most recent call last):
      File "/home/pablogsal/github/python/3.11/lel.py", line 8, in <module>
        _run_with_file_output()
        ^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/pablogsal/github/python/3.11/lel.py", line 6, in _run_with_file_output
        raise ValueError()
        ^^^^^^^^^^^^^^^^^^
    ValueError
    
  5. pablogsal commented on Jun 9, 2022

    @pablogsal
    pablogsal
    on Jun 9, 2022
    MemberAuthor
    More actions

    May be related to #93249

  6. markshannon commented on Jun 10, 2022

    @markshannon
    markshannon
    on Jun 10, 2022
    Member
    More actions

    It looks like the table is correct, but the parsing to get the line number is wrong.
    .__code__.co_positions() shows the correct positions, but .__code__.co_lines() shows the wrong line numbers.

  7. markshannon commented on Jun 10, 2022

    @markshannon
    markshannon
    on Jun 10, 2022
    Member
    More actions

    It's actually a bug in compiler front-end. It produces an instruction with lineno == end_lineno but end_col_offset < col_offset

  8. markshannon commented on Jun 10, 2022

    @markshannon
    markshannon
    on Jun 10, 2022
    Member
    More actions

    #93673

  9. markshannon
    added a commit that references this issue on Jun 14, 2022

    GH-93662: Make sure that column offsets are correct in multi-line met…

    2bf7475
  10. iritkatriel
    added a commit that references this issue on Jun 16, 2022

    pythonGH-93662: Make sure that column offsets are correct in multi-li…

    483f3d0
  11. iritkatriel commented on Jun 16, 2022

    @iritkatriel
    iritkatriel
    on Jun 16, 2022
    Member
    More actions

    Backport to 3.11: #93895

  12. pablogsal
    added a commit that references this issue on Jun 16, 2022

    [3.11] GH-93662: Make sure that column offsets are correct in multi-l…

    df091e1
  13. pablogsal
    closed this as completedon Jun 16, 2022
  14. serhiy-storchaka
    added a commit that references this issue on Jun 26, 2022

    Revert 30935 defer bpo45162 to 312 (#94285)

    1ffde3e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @markshannon
    markshannon

Labels

3.11only security fixesonly security fixesrelease-blocker

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.