Boost C++ Libraries: Ticket #2016: wrong default arguments in boost/python/exec.hpp https://svn.boost.org/trac10/ticket/2016 <p> 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. </p> <p> Consider this program: </p> <pre class="wiki">#include &lt;boost/python.hpp&gt; int main() { using namespace boost::python; Py_Initialize(); try { object foo = exec("a=5; print(a);"); } catch(error_already_set const &amp;) { PyErr_Print(); } return 0; } </pre><p> Expected output: </p> <pre class="wiki">5 </pre><p> Real output: </p> <pre class="wiki">Traceback (most recent call last): File "&lt;string&gt;", line 1, in &lt;module&gt; TypeError: 'NoneType' object does not support item assignment </pre><p> 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. </p> <p> Bye, </p> <blockquote> <p> Jan Scholz </p> </blockquote> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2016 Trac 1.4.3 schlotz <scholz@…> Tue, 17 Jun 2008 22:18:05 GMT attachment set https://svn.boost.org/trac10/ticket/2016 https://svn.boost.org/trac10/ticket/2016 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">change_default_object_to_dict.patch</span> </li> </ul> <p> Change exec default arguments from object() to dict() </p> Ticket Stefan Seefeld Mon, 15 Jun 2009 14:56:33 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/2016#comment:1 https://svn.boost.org/trac10/ticket/2016#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> 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. </p> Ticket