Skip to content

Commit adbd76e

Browse files
committed
Throw an error if someone assigns to a Context attribute that we did not define ourselves. Might improve ease of use
1 parent 2e10ed5 commit adbd76e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

context.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,15 @@ context_setattro(PyObject *self, PyObject *attrname, PyObject *py_value)
12821282
if ((setter = bsearch(&key, setters, NSETTERS, sizeof(struct setter_table),
12831283
compare_setters)) != NULL)
12841284
return setter->setter(context, py_value);
1285-
return 0;
1285+
/*
1286+
* if it's not an attribute we define, throw an error. The
1287+
* tradeoff is between ease of use and extensibility, and
1288+
* given that people are getting attribute names wrong this
1289+
* is worth trying. Back it out if there are complaints
1290+
*/
1291+
1292+
PyErr_SetString(PyExc_AttributeError, "No such attribute");
1293+
return -1;
12861294
}
12871295

12881296

0 commit comments

Comments
 (0)