Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 897b821

Browse files
committed
Make it illegal to assign to __debug__ as per Guido's request.
1 parent e280c06 commit 897b821

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

Python/compile.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ int Py_OptimizeFlag = 0;
6666
#define LATE_FUTURE \
6767
"from __future__ imports must occur at the beginning of the file"
6868

69+
#define ASSIGN_DEBUG \
70+
"can not assign to __debug__"
71+
6972
#define MANGLE_LEN 256
7073

7174
#define OFF(x) offsetof(PyCodeObject, x)
@@ -5181,8 +5184,16 @@ symtable_assign(struct symtable *st, node *n, int flag)
51815184
if (TYPE(tmp) == LPAR || TYPE(tmp) == LSQB) {
51825185
n = CHILD(n, 1);
51835186
goto loop;
5184-
} else if (TYPE(tmp) == NAME)
5187+
} else if (TYPE(tmp) == NAME) {
5188+
if (strcmp(STR(tmp), "__debug__") == 0) {
5189+
PyErr_SetString(PyExc_SyntaxError,
5190+
ASSIGN_DEBUG);
5191+
PyErr_SyntaxLocation(st->st_filename,
5192+
n->n_lineno);
5193+
st->st_errors++;
5194+
}
51855195
symtable_add_def(st, STR(tmp), DEF_LOCAL | flag);
5196+
}
51865197
return;
51875198
case dotted_as_name:
51885199
if (NCH(n) == 3)

0 commit comments

Comments
 (0)