diff -r fd69a6d1b0f0 Include/token.h --- a/Include/token.h Wed Oct 24 23:07:16 2012 +0300 +++ b/Include/token.h Thu Oct 25 03:03:39 2012 +0300 @@ -61,7 +61,7 @@ #define AT 49 #define RARROW 50 #define ELLIPSIS 51 -/* Don't forget to update the table _PyParser_TokenNames in tokenizer.c! */ +/* Don't forget to update the tables _PyParser_TokenNames and _PyParser_TokenDescs in tokenizer.c! */ #define OP 52 #define ERRORTOKEN 53 #define N_TOKENS 54 @@ -76,6 +76,7 @@ PyAPI_DATA(const char *) _PyParser_TokenNames[]; /* Token names */ +PyAPI_DATA(const char *) _PyParser_TokenDescs[]; /* Token descriptions */ PyAPI_FUNC(int) PyToken_OneChar(int); PyAPI_FUNC(int) PyToken_TwoChars(int, int); PyAPI_FUNC(int) PyToken_ThreeChars(int, int, int); diff -r fd69a6d1b0f0 Lib/test/test_genexps.py --- a/Lib/test/test_genexps.py Wed Oct 24 23:07:16 2012 +0300 +++ b/Lib/test/test_genexps.py Thu Oct 25 03:03:39 2012 +0300 @@ -87,7 +87,7 @@ >>> dict(a = i for i in range(10)) Traceback (most recent call last): ... - SyntaxError: invalid syntax + SyntaxError: invalid syntax - ')' expected Verify that parenthesis are required when used as a keyword argument value diff -r fd69a6d1b0f0 Lib/test/test_syntax.py --- a/Lib/test/test_syntax.py Wed Oct 24 23:07:16 2012 +0300 +++ b/Lib/test/test_syntax.py Thu Oct 25 03:03:39 2012 +0300 @@ -29,7 +29,7 @@ >>> obj.None = 1 Traceback (most recent call last): -SyntaxError: invalid syntax +SyntaxError: invalid syntax - name expected >>> None = 1 Traceback (most recent call last): @@ -110,17 +110,17 @@ >>> def f(x, None): ... pass Traceback (most recent call last): -SyntaxError: invalid syntax +SyntaxError: invalid syntax - ')' expected >>> def f(*None): ... pass Traceback (most recent call last): -SyntaxError: invalid syntax +SyntaxError: invalid syntax - ')' expected >>> def f(**None): ... pass Traceback (most recent call last): -SyntaxError: invalid syntax +SyntaxError: invalid syntax - name expected From ast_for_funcdef(): @@ -128,7 +128,7 @@ >>> def None(x): ... pass Traceback (most recent call last): -SyntaxError: invalid syntax +SyntaxError: invalid syntax - name expected From ast_for_call(): diff -r fd69a6d1b0f0 Parser/tokenizer.c --- a/Parser/tokenizer.c Wed Oct 24 23:07:16 2012 +0300 +++ b/Parser/tokenizer.c Thu Oct 25 03:03:39 2012 +0300 @@ -106,6 +106,70 @@ "" }; +static int _update_PyParser_TokenNames = Py_BUILD_ASSERT_EXPR( + Py_ARRAY_LENGTH(_PyParser_TokenNames) == N_TOKENS + 1); + +const char *_PyParser_TokenDescs[] = { + "end marker", /* ENDMARKER */ + "name", /* "NAME", */ + "number", /* NUMBER */ + "string", /* STRING" */ + "newline", /* NEWLINE */ + "indent", /* INDENT */ + "dedent", /* DEDENT */ + "'('", /* LPAR */ + "')'", /* RPAR */ + "'['", /* LSQB */ + "']'", /* RSQB */ + "':'", /* COLON */ + "','", /* COMMA */ + "';'", /* SEMI */ + "'+'", /* PLUS */ + "'-'", /* MINUS */ + "'*'", /* STAR */ + "'/'", /* SLASH */ + "'|'", /* VBAR */ + "'&'", /* AMPER */ + "'<'", /* LESS */ + "'>'", /* GREATER */ + "'='", /* EQUAL */ + "'.'", /* DOT */ + "'%'", /* PERCENT */ + "'{'", /* LBRACE */ + "'}'", /* RBRACE */ + "'=='", /* EQEQUAL */ + "'!='", /* NOTEQUAL */ + "'<='", /* LESSEQUAL */ + "'>='", /* GREATEREQUAL */ + "'~'", /* TILDE */ + "'^'", /* CIRCUMFLEX */ + "'<<'", /* LEFTSHIFT */ + "'>>'", /* RIGHTSHIFT */ + "'**'", /* DOUBLESTAR */ + "'+='", /* PLUSEQUAL */ + "'-='", /* MINEQUAL */ + "'*='", /* STAREQUAL */ + "'/='", /* SLASHEQUAL */ + "'%='", /* PERCENTEQUAL */ + "'&='", /* AMPEREQUAL */ + "'|='", /* VBAREQUAL */ + "'^='", /* CIRCUMFLEXEQUAL */ + "'<<='", /* LEFTSHIFTEQUAL */ + "'>>='", /* RIGHTSHIFTEQUAL */ + "'**='", /* DOUBLESTAREQUAL */ + "'//'", /* DOUBLESLASH */ + "'//='", /* DOUBLESLASHEQUAL */ + "'@'", /* AT */ + "'->'", /* RARROW */ + "'...'", /* ELLIPSIS */ + /* This table must match the #defines in token.h! */ + "OP", /* OP */ + "", /* */ + "" /* expected != -1) + msg_obj = PyUnicode_FromFormat( + "invalid syntax - %s expected", + _PyParser_TokenDescs[err->expected]); } break; case E_TOKEN: