[Python-Dev] Patch to use dict subclasses in eval(), exec

M.-A. Lemburg mal@lemburg.com
Tue, 29 Oct 2002 08:57:01 +0100


Jeff Epler wrote:
> Using dict subclasses in eval() and exec
> ----------------------------------------
> 
> With the attached patch, you can now use a dict subclass which implements
> __getitem__ as the global or builtin namespace for eval() and exec.
> 
> If you do not use the feature, the performance impact is low (<2%).
> The fast case adds only one test+branch to each eval_code() call (to
> set 'fastglobals' and 'slowbuiltins'), each lookup in globals (to
> check 'fastglobals'), and each lookup in builtins (to check 'slowbuiltins').
> 
> If you do use the feature, the performance impact is unfortunately
> quite substantial (400%).
> 
> If you use subclasses of dict with eval()/exec, but do not define __getitem__,
> the performance penalty is modest (~10%).

If all you want is a way to define a default value for a failing
dictionary lookup, wouldn't it be better to simply add this feature
to the standard dictionary implementation ?

I don't think that many people will use this feature, yet everybody
would pay for the performance hit.

-- 
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
_______________________________________________________________________
eGenix.com -- Makers of the Python mx Extensions: mxDateTime,mxODBC,...
Python Consulting:                               http://www.egenix.com/
Python Software:                    http://www.egenix.com/files/python/