[Boost-bugs] [Boost C++ Libraries] #2016: wrong default arguments in boost/python/exec.hpp

Subject: [Boost-bugs] [Boost C++ Libraries] #2016: wrong default arguments in boost/python/exec.hpp
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2008-06-17 22:15:12


#2016: wrong default arguments in boost/python/exec.hpp
---------------------------------------------------------+------------------
 Reporter: schlotz <scholz_at_[hidden]> | Owner: dave
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: Python
  Version: Boost Development Trunk | Severity: Problem
 Keywords: python exec exec_file eval default argument |
---------------------------------------------------------+------------------
 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

--
Ticket URL: <http://svn.boost.org/trac/boost/ticket/2016>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.


This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:58 UTC