[Python-Dev] Objecttype of 'locals' argument in PyEval_EvalCode
Hi all, I would like to know the definition of the 'locals' object given to PyEval_EvalCode. Has 'locals' to be a python dictionary or a subtype of a python dictionary, or is it enough if the object implements the necessary protocols? The python implementation behaves different for the two following code lines: from modul import symbol from modul import * In the case of the first one, it's enough if the object 'locals' implements the necessary protocols. The second one only works if the object 'locals' is a type or subtype of dictionary. The problem lies in Python-2.5/Python/ceval.c: static int import_all_from(PyObject *locals, PyObject *v) { ... 4046 value = PyObject_GetAttr(v, name); 4047 if (value == NULL) 4048err = -1; 4049 else >>> 4050err = PyDict_SetItem(locals, name, value); 4051 Py_DECREF(name); ... } Changing PyDict_SetItem in line 4050 with PyObject_SetAttr could fix it. Best Regards, Daniel ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Objecttype of 'locals' argument in PyEval_EvalCode
This seems a bug. In revision 36714 by Raymond Hettinger, the restriction that locals be a dict was relaxed to allow any mapping. On 11/29/06, Daniel Trstenjak <[EMAIL PROTECTED]> wrote: > > Hi all, > > I would like to know the definition of the 'locals' object given to > PyEval_EvalCode. Has 'locals' to be a python dictionary or a subtype > of a python dictionary, or is it enough if the object implements the > necessary protocols? > > The python implementation behaves different for the two following code > lines: > > from modul import symbol > from modul import * > > In the case of the first one, it's enough if the object 'locals' implements > the necessary protocols. The second one only works if the object 'locals' > is a type or subtype of dictionary. > > The problem lies in Python-2.5/Python/ceval.c: > > static int > import_all_from(PyObject *locals, PyObject *v) > { >... > 4046 value = PyObject_GetAttr(v, name); > 4047 if (value == NULL) > 4048err = -1; > 4049 else > >>> 4050err = PyDict_SetItem(locals, name, value); > 4051 Py_DECREF(name); >... > } > > Changing PyDict_SetItem in line 4050 with PyObject_SetAttr could fix it. > > > Best Regards, > Daniel > > ___ > Python-Dev mailing list > Python-Dev@python.org > http://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: > http://mail.python.org/mailman/options/python-dev/guido%40python.org > -- --Guido van Rossum (home page: http://www.python.org/~guido/) ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Objecttype of 'locals' argument in PyEval_EvalCode
Hi, On Wed, Nov 29, 2006 at 07:39:25AM -0800, Guido van Rossum wrote: > This seems a bug. In revision 36714 by Raymond Hettinger, the > restriction that locals be a dict was relaxed to allow any mapping. Mea culpa, I thought I reviewed this patch at the time. Fixed in r52862-52863. A bientot, Armin ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Objecttype of 'locals' argument in PyEval_EvalCode
[Guido van Rossum] > This seems a bug. In revision 36714 by Raymond Hettinger, > the restriction that locals be a dict was relaxed to allow > any mapping. [Armin Rigo] > Mea culpa, I thought I reviewed this patch at the time. > Fixed in r52862-52863. Armin, thanks for the check-ins. Daniel, thanks for finding one of the cases I missed. Will load a unittest for this one when I get a chance. Raymond ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com