mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Bug #132313 error message confusing for assignment in lambda.
They're actually complaining about something more specific, an assignment in a lambda as an actual argument, so that Python parses the lambda as if it were a keyword argument. Like f(lambda x: x[0]=42). The "lambda x: x[0]" part gets parsed as if it were a keyword, being bound to 42, and the resulting error msg didn't make much sense.
This commit is contained in:
parent
78349072f7
commit
4e30378e80
1 changed files with 8 additions and 1 deletions
|
@ -1522,7 +1522,14 @@ com_argument(struct compiling *c, node *n, PyObject **pkeywords)
|
||||||
m = CHILD(m, 0);
|
m = CHILD(m, 0);
|
||||||
} while (NCH(m) == 1);
|
} while (NCH(m) == 1);
|
||||||
if (TYPE(m) != NAME) {
|
if (TYPE(m) != NAME) {
|
||||||
|
/* f(lambda x: x[0] = 3) ends up getting parsed with
|
||||||
|
* LHS test = lambda x: x[0], and RHS test = 3.
|
||||||
|
* SF bug 132313 points out that complaining about a keyword
|
||||||
|
* then is very confusing.
|
||||||
|
*/
|
||||||
com_error(c, PyExc_SyntaxError,
|
com_error(c, PyExc_SyntaxError,
|
||||||
|
TYPE(m) == lambdef ?
|
||||||
|
"lambda cannot contain assignment" :
|
||||||
"keyword can't be an expression");
|
"keyword can't be an expression");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue