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

Incorrect line reported in syntax error #90395

Closed
arian-f mannequin opened this issue Jan 3, 2022 · 10 comments
Closed

Incorrect line reported in syntax error #90395

arian-f mannequin opened this issue Jan 3, 2022 · 10 comments
Labels
3.10 only security fixes 3.11 only security fixes type-bug An unexpected behavior, bug, or error

Comments

@arian-f
Copy link
Mannequin

arian-f mannequin commented Jan 3, 2022

BPO 46237
Nosy @terryjreedy, @ericvsmith, @aroberge, @pablogsal, @miss-islington
PRs
  • bpo-46237: Fix the line number of tokenizer errors inside f-strings #30463
  • [3.10] bpo-46237: Fix the line number of tokenizer errors inside f-strings (GH-30463) #30474
  • [3.9] bpo-46237: Fix the line number of tokenizer errors inside f-strings (GH-30463) #30543
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2022-01-11.16:39:56.487>
    created_at = <Date 2022-01-03.07:45:13.625>
    labels = ['type-bug', '3.10', '3.11']
    title = 'Incorrect line reported in syntax error'
    updated_at = <Date 2022-01-11.20:33:27.192>
    user = 'https://bugs.python.org/arian-f'

    bugs.python.org fields:

    activity = <Date 2022-01-11.20:33:27.192>
    actor = 'terry.reedy'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-01-11.16:39:56.487>
    closer = 'pablogsal'
    components = []
    creation = <Date 2022-01-03.07:45:13.625>
    creator = 'arian-f'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46237
    keywords = ['patch']
    message_count = 10.0
    messages = ['409567', '410007', '410009', '410039', '410055', '410059', '410061', '410314', '410319', '410328']
    nosy_count = 6.0
    nosy_names = ['terry.reedy', 'eric.smith', 'aroberge', 'pablogsal', 'miss-islington', 'arian-f']
    pr_nums = ['30463', '30474', '30543']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue46237'
    versions = ['Python 3.10', 'Python 3.11']

    @arian-f
    Copy link
    Mannequin Author

    arian-f mannequin commented Jan 3, 2022

    parsing this code results in a syntax error with an incorrect line number - it's always 1

    f'''
        { 1_a }'''
    

    resulting in:

    File "<stdin>", line 1
    ( 1_a )
    ^
    SyntaxError: invalid decimal literal

    an analogue error occurs when parsing a file instead of stdin.

    This bug looks like it's another instance of https://bugs.python.org/issue42209 - I commented there but there was no response for two weeks - I hope it's OK to post a new bug.

    python -VV
    Python 3.10.1 (tags/v3.10.1:2cd268a, Dec 6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)]

    @arian-f arian-f mannequin added 3.10 only security fixes type-bug An unexpected behavior, bug, or error labels Jan 3, 2022
    @terryjreedy
    Copy link
    Member

    Since bpo-42209 was closed, a new issue seems OK.

    As a result of the incorrect line number, IDLE highlights one of the opening quotes on line 1.

    @terryjreedy terryjreedy added 3.11 only security fixes labels Jan 7, 2022
    @pablogsal
    Copy link
    Member

    This also affects 3.9 I imagine, no?

    @aroberge
    Copy link
    Mannequin

    aroberge mannequin commented Jan 7, 2022

    This also affects 3.9 I imagine, no?

    Yes. And, from what I can tell, the same incorrect line is indicated at least all the way back to Python 3.6 (where it was "invalid token" instead of "invalid decimal literal).

    @pablogsal
    Copy link
    Member

    Please Andre and Terry, test this fix as much as you want. I am quite sure is correct, but it is far-reaching so I want to make sure every situation that we can think of is correct (and remains correct).

    @pablogsal
    Copy link
    Member

    I did some testing on my own using a code generator and a bunch of weird cases and I am confident this works. I am going to include this in the next alpha but will wait for your validation for some days before merging the backports.

    @pablogsal
    Copy link
    Member

    New changeset 6fa8b2c by Pablo Galindo Salgado in branch 'main':
    bpo-46237: Fix the line number of tokenizer errors inside f-strings (GH-30463)
    6fa8b2c

    @miss-islington
    Copy link
    Contributor

    New changeset 19a8550 by Miss Islington (bot) in branch '3.10':
    bpo-46237: Fix the line number of tokenizer errors inside f-strings (GH-30463)
    19a8550

    @pablogsal
    Copy link
    Member

    Backporting this to 3.9 is a bit more challenging and more changes are required, so I am not backporting for 3.9 to avoid unintended side effects.

    @terryjreedy
    Copy link
    Member

    I understand. I think that for IDLE, I should check that the error .text is in the line indicated, and if not, recover somehow rather than blindly marking the the indicated column. For a shell statement entry, try to find the right line. Not sure for an editor syntax error. This is a rare situation in any case.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.10 only security fixes 3.11 only security fixes type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants