Uploaded image for project: 'Data Management'
  1. Data Management
  2. DM-17662

PyBind 11 ack bug

    Details

    • Templates:
    • Story Points:
      2
    • Sprint:
      TSSW Sprint - Jan 21 - Feb 02
    • Team:
      Telescope and Site

      Description

      I have a Data struct that looks like this

      .h
      class AckCmd
      {
        public:
          SALData_ackcmdC ackData;
          AckCmd(int ack, int error, std::string result);
      };

      .cpp 
      AckCmd::AckCmd(int ack, int error, std::string result)
      {
        ackData.ack = ack;
        ackData.error = error;
        ackData.result = result;
      }
       

      I then am binding it as follows

       
      py::class_<AckCmd>(m,"AckCmd", py::module_local(), py::dynamic_attr())    
              .def(py::init<int, int, const std::string &>())   
              ;
       
      I have the `py::module_local()` tag because I was getting an `ImportError: generic_type: type "*" is already registered!` error. 
      I have the `py::dynamic_attr()` tag to set the `ack`, `error` and `result` attributes of the ackData object. 
       
      However, when I enter the following within a python shell
       
      >>> import SALPY_Library
      >>> myAck = SALPY_Library.AckCmd( 1, 2, "myack")
      >>> print(myAck.ack)
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      AttributeError: 'SALPY_Scheduler.AckCmd' object has no attribute 'ack'
      The attributes are not there. When using double tabbing to view the attributes of the object it doesn't show any of the attributes from the c++ struct.

      >>> myAck.__
      myAck._class(          myAck.doc             myAck.getattribute(   myAck.init_subclass(  myAck.ne(             myAck.repr(           myAck.subclasshook_(   
      myAck._delattr(        myAck.eq(             myAck.gt(             myAck.le(             myAck.new(            myAck.setattr_(        
      myAck._dict            myAck.format(         myAck.hash(           myAck.lt(             myAck.reduce(         myAck.sizeof_(         
      myAck._dir(            myAck.ge(             myAck.init(           myAck.module          myAck.reduce_ex(      myAck.str_(            

        Attachments

          Container Issues

            Issue Links

              Activity

                People

                • Assignee:
                  aheyer Andrew Heyer
                  Reporter:
                  jbuffill James Buffill [X] (Inactive)
                  Reviewers:
                  Dave Mills
                  Watchers:
                  Andrew Heyer, Dave Mills, James Buffill [X] (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  3 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Start date:
                    End date:

                    Summary Panel