[Python-checkins] CVS: python/dist/src/Parser parsetok.c,2.26,2.27
Guido van Rossum
gvanrossum@users.sourceforge.net
2001年7月17日 09:53:13 -0700
Update of /cvsroot/python/python/dist/src/Parser
In directory usw-pr-cvs1:/tmp/cvs-serv27024
Modified Files:
parsetok.c
Log Message:
Add a really stupid warning about 'yield' used as an identifier.
This is really stupid because it cannot be suppressed or altered using
the warning framework; that's because the warning framework is built
on Python interpreter internals, and the parser generator doesn't have
access to any of those (you cannot use anything of type PyObject * in
the parser).
But it's better than nothing, and implementing a proper check for this
appears to require modifying compile.c in a dozen places, for which I
don't have the stamina today. I promise we'll do better in 2.2a2.
At least it tells you the filename and line number (unlike the first
hack I considered :-).
Index: parsetok.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Parser/parsetok.c,v
retrieving revision 2.26
retrieving revision 2.27
diff -C2 -r2.26 -r2.27
*** parsetok.c 2001年07月16日 05:37:24 2.26
--- parsetok.c 2001年07月17日 16:53:11 2.27
***************
*** 93,96 ****
--- 93,99 ----
Return error code. */
+ static char yield_msg[] =
+ "%s:%d: Warning: 'yield' will become a reserved keyword in the future\n";
+
static node *
parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
***************
*** 136,139 ****
--- 139,151 ----
strncpy(str, a, len);
str[len] = '0円';
+
+ /* Warn about yield as NAME */
+ if (type == NAME && !ps->p_generators &&
+ len == 5 && str[0] == 'y' && strcmp(str, "yield") == 0)
+ PySys_WriteStderr(yield_msg,
+ err_ret->filename==NULL ?
+ "<string>" : err_ret->filename,
+ tok->lineno);
+
if ((err_ret->error =
PyParser_AddToken(ps, (int)type, str, tok->lineno,