Issue 16173: Wrong offset on SyntaxError when identifier contains non-ascii characters (original) (raw)
Issue16173
Created on 2012-10-09 10:23 by bmispelon, last changed 2022-04-11 14:57 by admin. This issue is now closed.
Messages (4) | ||
---|---|---|
msg172470 - (view) | Author: Baptiste Mispelon (bmispelon) * | Date: 2012-10-09 10:23 |
When a syntax error happens, the exception that gets printed has an extra line with a caret that helps locate the error. If the line also contains an identifier with non-ascii characters, then this caret is misaligned (too far on the right). I've investigated briefly and it seems that the offset attribute on the SyntaxError has a wrong value: for varname in ['a', 'é', '蟒']: # 1, 2 and 3 bytes try: exec("%s$" % varname) # SyntaxError except SyntaxError as e: print(e.offset) # should be 2 The example above prints 2, 3, and 4 when it should be printing 2 every time. It seems that the calculation of the offset takes into account the size in bytes instead of the size in characters. I've tested and reproduced the issue on 3.2.2 and on a recent clone of the mercurial repository (dd5e98ddcd39). | ||
msg172471 - (view) | Author: Ezio Melotti (ezio.melotti) * ![]() |
Date: 2012-10-09 10:25 |
See #2382. | ||
msg172488 - (view) | Author: R. David Murray (r.david.murray) * ![]() |
Date: 2012-10-09 15:30 |
Ezio, is there a reason you didn't close this as a duplicate? | ||
msg172551 - (view) | Author: Ezio Melotti (ezio.melotti) * ![]() |
Date: 2012-10-10 04:05 |
I was just in a hurry and didn't have time to check if they were indeed the same issue. Looks like they are, so I'm closing this as duplicate. |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:57:37 | admin | set | github: 60377 |
2012-10-10 04:05:00 | ezio.melotti | set | status: open -> closedversions: + Python 3.3superseder: [Py3k] SyntaxError cursor shifted if multibyte character is in line.messages: + resolution: duplicatestage: resolved |
2012-10-09 15:30:01 | r.david.murray | set | nosy: + r.david.murraymessages: + |
2012-10-09 10:25:19 | ezio.melotti | set | nosy: + ezio.melottimessages: + |
2012-10-09 10:23:53 | bmispelon | create |