mirror of
https://github.com/python/cpython.git
synced 2024-11-24 02:15:30 +08:00
gh-102310: Change error range for invalid bytes literals (#103663)
This commit is contained in:
parent
7bf94568a9
commit
0fd3891758
@ -1853,6 +1853,30 @@ x: *b
|
|||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
SyntaxError: invalid syntax
|
SyntaxError: invalid syntax
|
||||||
|
|
||||||
|
Invalid bytes literals:
|
||||||
|
|
||||||
|
>>> b"Ā"
|
||||||
|
Traceback (most recent call last):
|
||||||
|
...
|
||||||
|
b"Ā"
|
||||||
|
^^^
|
||||||
|
SyntaxError: bytes can only contain ASCII literal characters
|
||||||
|
|
||||||
|
>>> b"абвгде"
|
||||||
|
Traceback (most recent call last):
|
||||||
|
...
|
||||||
|
b"абвгде"
|
||||||
|
^^^^^^^^
|
||||||
|
SyntaxError: bytes can only contain ASCII literal characters
|
||||||
|
|
||||||
|
>>> b"abc ъющый" # first 3 letters are ascii
|
||||||
|
Traceback (most recent call last):
|
||||||
|
...
|
||||||
|
b"abc ъющый"
|
||||||
|
^^^^^^^^^^^
|
||||||
|
SyntaxError: bytes can only contain ASCII literal characters
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
Change the error range for invalid bytes literals.
|
@ -248,7 +248,8 @@ _PyPegen_parse_string(Parser *p, Token *t)
|
|||||||
const char *ch;
|
const char *ch;
|
||||||
for (ch = s; *ch; ch++) {
|
for (ch = s; *ch; ch++) {
|
||||||
if (Py_CHARMASK(*ch) >= 0x80) {
|
if (Py_CHARMASK(*ch) >= 0x80) {
|
||||||
RAISE_SYNTAX_ERROR(
|
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
|
||||||
|
t,
|
||||||
"bytes can only contain ASCII "
|
"bytes can only contain ASCII "
|
||||||
"literal characters");
|
"literal characters");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Loading…
Reference in New Issue
Block a user