[New-bugs-announce] [issue12983] byte string literals with invalid hex escape codes raise ValueError instead of SyntaxError

Ned Deily report at bugs.python.org
Thu Sep 15 00:51:36 CEST 2011


New submission from Ned Deily <nad at acm.org>:

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

----------
components: Interpreter Core
messages: 144059
nosy: ned.deily
priority: normal
severity: normal
status: open
title: byte string literals with invalid hex escape codes raise ValueError instead of SyntaxError
type: behavior
versions: Python 3.2, Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12983>
_______________________________________


More information about the New-bugs-announce mailing list