diff options
author | Tim Peters <tim.peters@gmail.com> | 2001-02-18 04:45:10 +0000 |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2001-02-18 04:45:10 +0000 |
commit | 64eaf7d7fb5334731050216356165ab1d8d6b2af (patch) | |
tree | 590f7db45afd49d8e45d5450397dab6106cef824 /Python/compile.c | |
parent | 09c1d1d3ff5871fc5a3a4dc92f2282b1c98fa840 (diff) | |
download | cpython-64eaf7d7fb5334731050216356165ab1d8d6b2af.tar.gz |
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.
Diffstat (limited to 'Python/compile.c')
-rw-r--r-- | Python/compile.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/Python/compile.c b/Python/compile.c index c562def21c..7b1740433d 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -1522,8 +1522,15 @@ com_argument(struct compiling *c, node *n, PyObject **pkeywords) m = CHILD(m, 0); } while (NCH(m) == 1); 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, - "keyword can't be an expression"); + TYPE(m) == lambdef ? + "lambda cannot contain assignment" : + "keyword can't be an expression"); } else { PyObject *v = PyString_InternFromString(STR(m)); |