On Fri, Jan 20, 2012 at 11:58 PM, Stefan Behnel <stefan...@behnel.de> wrote:

> Chris Colbert, 19.01.2012 09:18:
> > If it doesn't pass PyDict_CheckExact you won't be able to use it as the
> > globals to eval or exec.
>
> What makes you say that? I tried and it worked for me, all the way back to
> Python 2.4:
>
>
Ah, you're right. I was mixing up issues I'd dealt with recently. The issue
with the eval/exec is that the globals must be a dict (or dict subclass)
whereas the locals can be a mapping. However, if you subclass dict for your
globals, any overridden __getitem__ or __setitem__ will not be called.
There is this line for eval/exec in ceval.c

if (!PyDict_Check(globals)) {
        PyErr_SetString(PyExc_TypeError,
            "exec: arg 2 must be a dictionary or None");
        return -1;

}

This allows the eval loop to use PyDict_GetItem on the globals instead of
PyObject_GetItem, so no subclass method overrides will be called.
_______________________________________________
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel

Reply via email to