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

Fix attributes of syntax errors raized in the tokenizer #83400

Closed
serhiy-storchaka opened this issue Jan 5, 2020 · 5 comments
Closed

Fix attributes of syntax errors raized in the tokenizer #83400

serhiy-storchaka opened this issue Jan 5, 2020 · 5 comments
Labels
3.8 only security fixes 3.9 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member

BPO 39219
Nosy @terryjreedy, @serhiy-storchaka, @miss-islington
PRs
  • bpo-39219: Fix SyntaxError attributes in the tokenizer. #17828
  • [3.8] bpo-39219: Fix SyntaxError attributes in the tokenizer. (GH-17828) #18479
  • 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 2020-02-12.10:57:48.919>
    created_at = <Date 2020-01-05.11:33:45.581>
    labels = ['interpreter-core', 'type-bug', '3.8', '3.9']
    title = 'Fix attributes of syntax errors raized in the tokenizer'
    updated_at = <Date 2020-02-12.10:57:48.918>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2020-02-12.10:57:48.918>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-02-12.10:57:48.919>
    closer = 'serhiy.storchaka'
    components = ['Interpreter Core']
    creation = <Date 2020-01-05.11:33:45.581>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 39219
    keywords = ['patch']
    message_count = 5.0
    messages = ['359331', '359769', '359791', '361873', '361875']
    nosy_count = 3.0
    nosy_names = ['terry.reedy', 'serhiy.storchaka', 'miss-islington']
    pr_nums = ['17828', '18479']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue39219'
    versions = ['Python 3.8', 'Python 3.9']

    @serhiy-storchaka
    Copy link
    Member Author

    SyntaxError can be raised at different stages of compiling. In some places the source text is not available and should be read from the file using the file name. Which does not work in case of compiling a string or reading from stdin.

    >>> 0z
      File "<stdin>", line 1
        0z
         ^
    SyntaxError: invalid syntax
    >>> 0xz
      File "<stdin>", line 1
    SyntaxError: invalid hexadecimal literal

    In the second example above the source line and the caret are absent in REPL.

    The proposed PR fixes two errors in raising a SyntaxError in the tokenizer.

    1. The text of the source line was not set if an exception was raised in the tokenizer. Since most of these exceptions (with more detailed description) were added in 3.8 I consider this a regressions.

    2. The offset attribute was an offset in bytes. Now it is an offset in characters.

    It only fixes errors in the tokenizer. There are similar bugs in other parts of the compiler.

    This issue is based on the article https://aroberge.blogspot.com/2019/12/a-tiny-python-exception-oddity.html .

    @serhiy-storchaka serhiy-storchaka added 3.8 only security fixes 3.9 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Jan 5, 2020
    @terryjreedy
    Copy link
    Member

    On entry of '0xz', IDLE from 3.6 to date highlights the '0x' part of the original entry. I presume it can do this because it ignores the text attribute, and because bytes == chars for at least '0x'.

    The 'proposed PR' is not listed here. Is it not yet submitted, or is the issue number wrong?

    @serhiy-storchaka
    Copy link
    Member Author

    Sorry, wrong issue number.

    @serhiy-storchaka
    Copy link
    Member Author

    New changeset 0cc6b5e by Serhiy Storchaka in branch 'master':
    bpo-39219: Fix SyntaxError attributes in the tokenizer. (GH-17828)
    0cc6b5e

    @miss-islington
    Copy link
    Contributor

    New changeset efd878c by Miss Islington (bot) in branch '3.8':
    bpo-39219: Fix SyntaxError attributes in the tokenizer. (GH-17828)
    efd878c

    @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.8 only security fixes 3.9 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants