summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2019-08-25 13:45:40 (GMT)
committerGitHub <noreply@github.com>2019-08-25 13:45:40 (GMT)
commit5dbe0f59b7a4f39c7c606b48056bc29e406ebf78 (patch)
tree9dd53ae948d0e49719d85d5e7814a6b1db61fdf3 /Include
parentce6a070414ed1e1374d1e6212bfbff61b6d5d755 (diff)
downloadcpython-5dbe0f59b7a4f39c7c606b48056bc29e406ebf78.zip
cpython-5dbe0f59b7a4f39c7c606b48056bc29e406ebf78.tar.gz
cpython-5dbe0f59b7a4f39c7c606b48056bc29e406ebf78.tar.bz2
bpo-37757: Disallow PEP 572 cases that expose implementation details (GH-15131)
- drop TargetScopeError in favour of raising SyntaxError directly as per the updated PEP 572 - comprehension iteration variables are explicitly local, but named expression targets in comprehensions are nonlocal or global. Raise SyntaxError as specified in PEP 572 - named expression targets in the outermost iterable of a comprehension have an ambiguous target scope. Avoid resolving that question now by raising SyntaxError. PEP 572 originally required this only for cases where the bound name conflicts with the iteration variable in the comprehension, but CPython can't easily restrict the exception to that case (as it doesn't know the target variable names when visiting the outermost iterator expression)
Diffstat (limited to 'Include')
-rw-r--r--Include/pyerrors.h1
-rw-r--r--Include/symtable.h3
2 files changed, 3 insertions, 1 deletions
diff --git a/Include/pyerrors.h b/Include/pyerrors.h
index 94af3cb..5125a51 100644
--- a/Include/pyerrors.h
+++ b/Include/pyerrors.h
@@ -97,7 +97,6 @@ PyAPI_DATA(PyObject *) PyExc_NotImplementedError;
PyAPI_DATA(PyObject *) PyExc_SyntaxError;
PyAPI_DATA(PyObject *) PyExc_IndentationError;
PyAPI_DATA(PyObject *) PyExc_TabError;
-PyAPI_DATA(PyObject *) PyExc_TargetScopeError;
PyAPI_DATA(PyObject *) PyExc_ReferenceError;
PyAPI_DATA(PyObject *) PyExc_SystemError;
PyAPI_DATA(PyObject *) PyExc_SystemExit;
diff --git a/Include/symtable.h b/Include/symtable.h
index 9392e64..5dcfa7e 100644
--- a/Include/symtable.h
+++ b/Include/symtable.h
@@ -58,6 +58,8 @@ typedef struct _symtable_entry {
unsigned ste_needs_class_closure : 1; /* for class scopes, true if a
closure over __class__
should be created */
+ unsigned ste_comp_iter_target : 1; /* true if visiting comprehension target */
+ int ste_comp_iter_expr; /* non-zero if visiting a comprehension range expression */
int ste_lineno; /* first line of block */
int ste_col_offset; /* offset of first line of block */
int ste_opt_lineno; /* lineno of last exec or import * */
@@ -94,6 +96,7 @@ PyAPI_FUNC(void) PySymtable_Free(struct symtable *);
#define DEF_FREE_CLASS 2<<5 /* free variable from class's method */
#define DEF_IMPORT 2<<6 /* assignment occurred via import */
#define DEF_ANNOT 2<<7 /* this name is annotated */
+#define DEF_COMP_ITER 2<<8 /* this name is a comprehension iteration variable */
#define DEF_BOUND (DEF_LOCAL | DEF_PARAM | DEF_IMPORT)