Why can "exec ... in d" delete items from d?

Christopher A. Craig list-python at ccraig.org
Wed Aug 28 06:59:48 CEST 2002

"Troels Therkelsen" <t_therkelsen at hotmail.com> writes:

> Have I stumbled unto an esoteric bug, or is this just an undocumented
> feature of exec?

Hmm, I'm not sure which it is, but it's not the bug/undocumented
feature you think it is.  The documentation specifies that the
namespaces should be dictionaries, not mapping types or subclasses of
dictionaries.  So when you passed it something that was subclassed
from dict it ran PyDict_Check() on it and then, when it passed,
treated it like a native dict.

If there is a bug, it is that exec should have refused to use your
non-dict like it would a mapping not subclassed from dict.

Christopher A. Craig <list-python at ccraig.org>
Love does no wrong to a neighbor; therefore love is
the fulfillment of the law - Romans 13:10

More information about the Python-list mailing list