This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Refactor error messages in symtable.c
Type: Stage:
Components: Interpreter Core Versions: Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: christian.heimes, levkivskyi, python-dev
Priority: normal Keywords: patch

Created on 2016-09-12 11:43 by levkivskyi, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
refactor-error-msg.diff levkivskyi, 2016-09-12 11:43 review
refactor-error-msg-v2.diff levkivskyi, 2016-09-21 15:37 review
Messages (4)
msg276024 - (view) Author: Ivan Levkivskyi (levkivskyi) * (Python committer) Date: 2016-09-12 11:43
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.
msg277150 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2016-09-21 14:56
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;
    }
    ...
}
msg277164 - (view) Author: Ivan Levkivskyi (levkivskyi) * (Python committer) Date: 2016-09-21 15:37
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).
msg277291 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-09-23 18:26
New changeset 966b57281536 by Christian Heimes in branch '3.6':
Issue #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 #28100: Refactor error messages, patch by Ivan Levkivskyi
https://hg.python.org/cpython/rev/a953112116ac
History
Date User Action Args
2022-04-11 14:58:36adminsetgithub: 72287
2016-10-07 22:28:59levkivskyisetstatus: open -> closed
resolution: fixed
2016-09-23 18:26:55python-devsetnosy: + python-dev
messages: + msg277291
2016-09-21 15:37:15levkivskyisetfiles: + refactor-error-msg-v2.diff

messages: + msg277164
2016-09-21 14:56:00christian.heimessetmessages: + msg277150
2016-09-12 11:43:04levkivskyicreate