Merge from 3.6.
This commit is contained in:
commit
9a8e569865
|
@ -92,6 +92,13 @@ f'{a * x()}'"""
|
||||||
exec(c)
|
exec(c)
|
||||||
self.assertEqual(x[0], 'foo3')
|
self.assertEqual(x[0], 'foo3')
|
||||||
|
|
||||||
|
def test_compile_time_concat_errors(self):
|
||||||
|
self.assertAllRaise(SyntaxError,
|
||||||
|
'cannot mix bytes and nonbytes literals',
|
||||||
|
[r"""f'' b''""",
|
||||||
|
r"""b'' f''""",
|
||||||
|
])
|
||||||
|
|
||||||
def test_literal(self):
|
def test_literal(self):
|
||||||
self.assertEqual(f'', '')
|
self.assertEqual(f'', '')
|
||||||
self.assertEqual(f'a', 'a')
|
self.assertEqual(f'a', 'a')
|
||||||
|
|
|
@ -5147,7 +5147,8 @@ parsestrplus(struct compiling *c, const node *n)
|
||||||
/* Check that we're not mixing bytes with unicode. */
|
/* Check that we're not mixing bytes with unicode. */
|
||||||
if (i != 0 && bytesmode != this_bytesmode) {
|
if (i != 0 && bytesmode != this_bytesmode) {
|
||||||
ast_error(c, n, "cannot mix bytes and nonbytes literals");
|
ast_error(c, n, "cannot mix bytes and nonbytes literals");
|
||||||
Py_DECREF(s);
|
/* s is NULL if the current string part is an f-string. */
|
||||||
|
Py_XDECREF(s);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
bytesmode = this_bytesmode;
|
bytesmode = this_bytesmode;
|
||||||
|
@ -5161,11 +5162,12 @@ parsestrplus(struct compiling *c, const node *n)
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
goto error;
|
goto error;
|
||||||
} else {
|
} else {
|
||||||
|
/* A string or byte string. */
|
||||||
|
assert(s != NULL && fstr == NULL);
|
||||||
|
|
||||||
assert(bytesmode ? PyBytes_CheckExact(s) :
|
assert(bytesmode ? PyBytes_CheckExact(s) :
|
||||||
PyUnicode_CheckExact(s));
|
PyUnicode_CheckExact(s));
|
||||||
|
|
||||||
/* A string or byte string. */
|
|
||||||
assert(s != NULL && fstr == NULL);
|
|
||||||
if (bytesmode) {
|
if (bytesmode) {
|
||||||
/* For bytes, concat as we go. */
|
/* For bytes, concat as we go. */
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
|
@ -5177,7 +5179,6 @@ parsestrplus(struct compiling *c, const node *n)
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
assert(s != NULL && fstr == NULL);
|
|
||||||
/* This is a regular string. Concatenate it. */
|
/* This is a regular string. Concatenate it. */
|
||||||
if (FstringParser_ConcatAndDel(&state, s) < 0)
|
if (FstringParser_ConcatAndDel(&state, s) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
Loading…
Reference in New Issue