3.4 C++ Data Members or Python Class Attributes

Some of the implicit type conversions in C++ are very hard to emulate in Python bindings generated by SIP. For instance, the straightforward translation of the C++ snippet

    SoMaterial *redPlastic = new SoMaterial;
    // Now, the statement
    redPlastic->shininess = 0.5;
    // works because of the operator
    // float SoMFField::operator=(float);
    // which is declared by means of a macro in Inventor/fields/SoSubField.
to the Python snippet
    redPlastic = SoMaterial()
    redPlastic.shininess = 0.5
fails, because IVuPy does not (yet) provide the means to do the implicit type conversion.

Work-arounds are:

    redPlastic = SoMaterial()
or (more dangerous and therefore less good)
    redPlastic = SoMaterial()
    # The Python API of SoMFFloat has been extended with respect to its C++ API
    # to allow this:
    redPlastic.shininess = SoMFFloat(0.5)

The latter work-around is more dangerous because if you mistype shininess in

    redPlastic.shininess = SoMFFloat(0.5)
a new attribute is (silently) created. The first work-around fails immediately when you mistype shininess.

Warning: Attributes are not shown in the result from
In my opinion this is a SIP-4.3 bug or implementation quirk. You have to look into the Coin documentation or .sip files to find the attributes.

Note: Check whether the new %SetCode directive in SIP-4.3 allows to implement the straightforward translation.