[Cython] Speedup module-level lookup

Stefan Behnel stefan_ml at behnel.de
Sat Jan 21 06:58:14 CET 2012

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:

Python 2.4.6 (#2, Jan 21 2010, 23:45:25)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class MyDict(dict): pass
>>> eval('1+1', MyDict())
>>> exec '1+1' in MyDict()

I only see a couple of calls to PyDict_CheckExact() in CPython's sources
and they usually seem to be related to special casing for performance
reasons. Nothing that should impact a module's globals.

Besides, Cython controls its own language usages of eval and exec.


More information about the cython-devel mailing list