cpython: 6bd21268876e (original) (raw)
--- a/Lib/test/test_py3kwarn.py +++ b/Lib/test/test_py3kwarn.py @@ -307,6 +307,11 @@ class TestPy3KWarnings(unittest.TestCase w.reset() self.assertWarning(sequenceIncludes(range(3), 2), w, seq_warn)
- def test_nonascii_bytes_literals(self):
expected = "non-ascii bytes literals not supported in 3.x"[](#l1.8)
with check_py3k_warnings((expected, SyntaxWarning)):[](#l1.9)
exec "b'\xbd'"[](#l1.10)
+ class TestStdlibRemovals(unittest.TestCase):
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ What's New in Python 2.7.8? Core and Builtins ----------------- +- Issue #19656: Running Python with the -3 option now also warns about
- Issue #21523: Fix over-pessimistic computation of the stack effect of some opcodes in the compiler. This also fixes a quadratic compilation time issue noticeable when compiling code with a large number of "and"
--- a/Python/ast.c +++ b/Python/ast.c @@ -37,7 +37,7 @@ static expr_ty ast_for_testlist_comp(str static expr_ty ast_for_call(struct compiling *, const node *, expr_ty); static PyObject *parsenumber(struct compiling *, const char *); -static PyObject *parsestr(struct compiling *, const char *); +static PyObject *parsestr(struct compiling *, const node *n, const char *); static PyObject *parsestrplus(struct compiling *, const node *n); #ifndef LINENO @@ -3444,13 +3444,14 @@ decode_unicode(struct compiling *c, cons
- parsestr parses it, and returns the decoded Python string object. */ static PyObject * -parsestr(struct compiling *c, const char *s) +parsestr(struct compiling *c, const node *n, const char *s) {
size_t len;[](#l3.19)
size_t len, i;[](#l3.20) int quote = Py_CHARMASK(*s);[](#l3.21) int rawmode = 0;[](#l3.22) int need_encoding;[](#l3.23) int unicode = c->c_future_unicode;[](#l3.24)
int bytes = 0;[](#l3.25)
if (isalpha(quote) || quote == '_') { if (quote == 'u' || quote == 'U') { @@ -3460,6 +3461,7 @@ parsestr(struct compiling *c, const char if (quote == 'b' || quote == 'B') { quote = *++s; unicode = 0;
bytes = 1;[](#l3.33) }[](#l3.34) if (quote == 'r' || quote == 'R') {[](#l3.35) quote = *++s;[](#l3.36)
@@ -3489,6 +3491,16 @@ parsestr(struct compiling *c, const char return NULL; } }
if (Py_Py3kWarningFlag && bytes) {[](#l3.41)
for (i = 0; i < len; i++) {[](#l3.42)
if ((unsigned char)s[i] > 127) {[](#l3.43)
if (!ast_warn(c, n,[](#l3.44)
"non-ascii bytes literals not supported in 3.x"))[](#l3.45)
return NULL;[](#l3.46)
break;[](#l3.47)
}[](#l3.48)
}[](#l3.49)
}[](#l3.50)
#ifdef Py_USING_UNICODE if (unicode || Py_UnicodeFlag) { return decode_unicode(c, s, len, rawmode, c->c_encoding); @@ -3531,11 +3543,11 @@ parsestrplus(struct compiling *c, const PyObject *v; int i; REQ(CHILD(n, 0), STRING);
if ((v = parsestr(c, STR(CHILD(n, 0)))) != NULL) {[](#l3.58)
if ((v = parsestr(c, n, STR(CHILD(n, 0)))) != NULL) {[](#l3.59) /* String literal concatenation */[](#l3.60) for (i = 1; i < NCH(n); i++) {[](#l3.61) PyObject *s;[](#l3.62)
s = parsestr(c, STR(CHILD(n, i)));[](#l3.63)
s = parsestr(c, n, STR(CHILD(n, i)));[](#l3.64) if (s == NULL)[](#l3.65) goto onError;[](#l3.66) if (PyString_Check(v) && PyString_Check(s)) {[](#l3.67)