summaryrefslogtreecommitdiffstats
path: root/Parser
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-07-17 16:53:11 (GMT)
committerGuido van Rossum <guido@python.org>2001-07-17 16:53:11 (GMT)
commitda62ecc9aaf6266e10ee6844d81f6145b0ec8413 (patch)
tree5abdf48783b0d89fca72e664f67ec80cd829c808 /Parser
parent16649a803b154ce7fd667f7e4211eb17091fe8b9 (diff)
downloadcpython-da62ecc9aaf6266e10ee6844d81f6145b0ec8413.zip
cpython-da62ecc9aaf6266e10ee6844d81f6145b0ec8413.tar.gz
cpython-da62ecc9aaf6266e10ee6844d81f6145b0ec8413.tar.bz2
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 :-).
Diffstat (limited to 'Parser')
-rw-r--r--Parser/parsetok.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/Parser/parsetok.c b/Parser/parsetok.c
index 6017e5f..386b82f 100644
--- a/Parser/parsetok.c
+++ b/Parser/parsetok.c
@@ -92,6 +92,9 @@ PyParser_ParseFileFlags(FILE *fp, char *filename, grammar *g, int start,
/* Parse input coming from the given tokenizer structure.
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,
int flags)
@@ -135,6 +138,15 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
if (len > 0)
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,
&(err_ret->expected))) != E_OK) {