[issue37377] unicode error should raise a value error

2019-06-23 Thread hai shi


hai shi  added the comment:

Got it, thank for your detailed explanation, steven.

--
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37377] unicode error should raise a value error

2019-06-23 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

It is a *syntax* error. You have written bad syntax, just as the error message 
says. Your \xXX code is too short, only 1 hex digit instead of 2. I disagree 
that this should be a value error: it isn't a bad value, it is bad syntax.

I don't know what the context of the BDFL pronouncement in PEP 223 was, but I 
think it was decided later that Guido wrong because the error in Python 2.4 and 
2.5 was UnicodeDecodeError and then changed to SyntaxError in 2.6 (probably to 
match Python 3, I guess).

In Python 3, both unicode and bytes strings give a syntax error for this error.

--
nosy: +steven.daprano
versions: +Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37377] unicode error should raise a value error

2019-06-23 Thread hai shi


New submission from hai shi :

>>> "\x1"
  File "", line 1
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in 
position 0-2: truncated \xXX escape

I think rasing the valueError would be exact.(pep223 agree this behavior: 
https://www.python.org/dev/peps/pep-0223/#bdfl-pronouncements).

And I think the error type could be changed in:
https://github.com/python/cpython/blob/master/Python/ast.c#L682

--
components: Interpreter Core
messages: 346321
nosy: shihai1991
priority: normal
severity: normal
status: open
title: unicode error should raise a value error
type: behavior

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com