Opened 14 years ago
Closed 13 years ago
#2016 closed Bugs (fixed)
wrong default arguments in boost/python/exec.hpp
Reported by: | Owned by: | Dave Abrahams | |
---|---|---|---|
Milestone: | To Be Determined | Component: | python USE GITHUB |
Version: | Boost Development Trunk | Severity: | Problem |
Keywords: | python exec exec_file eval default argument | Cc: |
Description
Calling boost::python::exec, exec_file and eval without the second and third argument, makes the default arguments create 'object's where 'dict's are neccessary.
Consider this program:
#include <boost/python.hpp> int main() { using namespace boost::python; Py_Initialize(); try { object foo = exec("a=5; print(a);"); } catch(error_already_set const &) { PyErr_Print(); } return 0; }
Expected output:
5
Real output:
Traceback (most recent call last): File "<string>", line 1, in <module> TypeError: 'NoneType' object does not support item assignment
A possible fix is to change the default arguments to exec, exec_file and eval in exec.hpp from ...=object() to ...=dict(), see the attached patch to boost/python/exec.hpp I'm not sure if it would make sense to change the type of the arguments from object to dict as well.
Bye,
Jan Scholz
Attachments (1)
Change History (2)
by , 14 years ago
Attachment: | change_default_object_to_dict.patch added |
---|
comment:1 by , 13 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I have just checked in a different fix for this problem. The global dictionary should default to, well, the existing global dictionary. The local defaults to be the same as global.
Change exec default arguments from object() to dict()