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

Refactor error messages in symtable.c #72287

Closed
ilevkivskyi opened this issue Sep 12, 2016 · 4 comments
Closed

Refactor error messages in symtable.c #72287

ilevkivskyi opened this issue Sep 12, 2016 · 4 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@ilevkivskyi
Copy link
Member

BPO 28100
Nosy @tiran, @ilevkivskyi
Files
  • refactor-error-msg.diff
  • refactor-error-msg-v2.diff
  • 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 2016-10-07.22:28:59.790>
    created_at = <Date 2016-09-12.11:43:04.186>
    labels = ['interpreter-core']
    title = 'Refactor error messages in symtable.c'
    updated_at = <Date 2016-10-07.22:28:59.789>
    user = 'https://github.com/ilevkivskyi'

    bugs.python.org fields:

    activity = <Date 2016-10-07.22:28:59.789>
    actor = 'levkivskyi'
    assignee = 'none'
    closed = True
    closed_date = <Date 2016-10-07.22:28:59.790>
    closer = 'levkivskyi'
    components = ['Interpreter Core']
    creation = <Date 2016-09-12.11:43:04.186>
    creator = 'levkivskyi'
    dependencies = []
    files = ['44592', '44782']
    hgrepos = []
    issue_num = 28100
    keywords = ['patch']
    message_count = 4.0
    messages = ['276024', '277150', '277164', '277291']
    nosy_count = 3.0
    nosy_names = ['christian.heimes', 'python-dev', 'levkivskyi']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue28100'
    versions = ['Python 3.6']

    @ilevkivskyi
    Copy link
    Member Author

    Patch with added comment and a minor refactoring to error messages in symtable.c

    Now the error message is simply always overwritten by any more "severe" SyntaxError found in the same block.

    @ilevkivskyi ilevkivskyi added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Sep 12, 2016
    @tiran
    Copy link
    Member

    tiran commented Sep 21, 2016

    Please rewrite the patch to use if / else if / else, e.g.

     if (cur & (DEF_LOCAL | USE | DEF_ANNOT)) {
        ...
        if (cur & USE) {
            msg = GLOBAL_AFTER_USE;
        } else if (cur & DEF_LOCAL) {
            msg = GLOBAL_AFTER_ASSIGN;
        } else {  /* DEF_ANNOT */
            msg = GLOBAL_ANNOT;
        }
        ...
    }

    @ilevkivskyi
    Copy link
    Member Author

    Here is the patch for 3.6 with requested changes.

    While playing with this a bit more, I discovered that the error message in this case (if no value is actually assigned):

    def f():
        x: int
        global x

    could be misleading. Therefore I changed the order of DEF_LOCAL and DEF_ANNOT to get a more clear error message for such cases (this does not spoil error messages in other cases).

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Sep 23, 2016

    New changeset 966b57281536 by Christian Heimes in branch '3.6':
    Issue bpo-28100: Refactor error messages, patch by Ivan Levkivskyi
    https://hg.python.org/cpython/rev/966b57281536

    New changeset a953112116ac by Christian Heimes in branch 'default':
    Issue bpo-28100: Refactor error messages, patch by Ivan Levkivskyi
    https://hg.python.org/cpython/rev/a953112116ac

    @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
    interpreter-core (Objects, Python, Grammar, and Parser dirs)
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants