classification
Title: byte string literals with invalid hex escape codes raise ValueError instead of SyntaxError
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.4, Python 3.2, Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: abacabadabacaba, benjamin.peterson, ezio.melotti, ned.deily, python-dev, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2011-09-14 22:51 by ned.deily, last changed 2013-02-10 17:19 by serhiy.storchaka. This issue is now closed.

Files
File name Uploaded Description Edit
parse_strlit_error.patch serhiy.storchaka, 2013-01-15 21:37 review
Messages (5)
msg144059 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2011-09-14 22:51
In behavior carried over from Python 2 string literals, Python 3 byte string literals raise a less helpful ValueError exception when an invalid hex escape code is given:

    >>> x = b'\x0'
    ValueError: invalid \x escape

A string literal raises a SyntaxError and a full traceback including line number:

    >>> x = '\x0'
      File "<stdin>", line 1
    SyntaxError: (unicode error) 'unicodeescape' codec can't decode
     bytes in position 0-2: end of string in escape sequence
msg180054 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-01-15 21:37
Here is a patch which include position number in the invalid bytes exception, wrap it into SyntaxError, and adds tests for bytes and strings.
msg181431 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-02-05 12:56
Ping.
msg181812 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2013-02-10 15:18
LGTM
msg181815 - (view) Author: Roundup Robot (python-dev) Date: 2013-02-10 15:45
New changeset 305210a08fc9 by Serhiy Storchaka in branch '3.2':
Issue #12983: Bytes literals with invalid \x escape now raise a SyntaxError
http://hg.python.org/cpython/rev/305210a08fc9

New changeset d5b731446a91 by Serhiy Storchaka in branch '3.3':
Issue #12983: Bytes literals with invalid \x escape now raise a SyntaxError
http://hg.python.org/cpython/rev/d5b731446a91

New changeset fe410292cba6 by Serhiy Storchaka in branch 'default':
Issue #12983: Bytes literals with invalid \x escape now raise a SyntaxError
http://hg.python.org/cpython/rev/fe410292cba6
History
Date User Action Args
2013-02-10 17:19:11serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2013-02-10 15:45:32python-devsetnosy: + python-dev
messages: + msg181815
2013-02-10 15:18:40benjamin.petersonsetmessages: + msg181812
2013-02-09 21:08:26serhiy.storchakasetnosy: + benjamin.peterson
2013-02-05 12:56:18serhiy.storchakasetmessages: + msg181431
2013-01-31 14:28:36serhiy.storchakasetassignee: serhiy.storchaka
2013-01-15 21:37:19serhiy.storchakasetfiles: + parse_strlit_error.patch

versions: + Python 3.4
keywords: + patch
nosy: + serhiy.storchaka

messages: + msg180054
stage: test needed -> patch review
2011-09-15 14:22:56abacabadabacabasetnosy: + abacabadabacaba
2011-09-15 03:17:26ezio.melottisetnosy: + ezio.melotti

stage: test needed
2011-09-14 22:51:36ned.deilycreate