Adding a 'SUN' via lamp_add() actually adds a 'HEMI'. Bug? If I fire the operator afterwards from a button, it doesn't work properly. I've other operators with other lamp types and those are working quite well as expected. But this one stole me a hour or two. Before I open a bug report I would like to check with more experienced developers (I'm quite new to Python) if I'm doing it wrong. Details are given in the following code:

class RfB_OT_OBJECT_AddLightDay(bpy.types.Operator):
bl_idname = "rfb.object_add_light_day"
bl_label = "Add DayLight"
bl_description = ""
bl_options = {"REGISTER", "UNDO"}

def execute(self, context):
    #
    # FIXME:  Adding the lamp as type 'SUN' here from operator, will add
    #         the lamp as 'HEMI'. Changing C.data.type to 'SUN' direct
    #         afterwards explicitly doesn't work, have to do it a few
    #         lines later. See QUICKFIX.
    # DATE:   2018-01-21
    # AUTHOR: Timm Wimmers
    # STATUS: assigned to self
    # BL_VER: 2.79
    #
    bpy.ops.object.lamp_add(type='SUN')  # BUG?: will be added as 'HEMI'
    _tmp = {'material': None, 'lamp': bpy.context.active_object.data}
    bpy.ops.rfb.node_add_nodetree(_tmp, idtype='lamp')
    bpy.context.object.data.renderman.renderman_type = 'SKY'
    # QUICKFIX: change late explicitly
    bpy.context.object.data.type = 'SUN'
    return {"FINISHED"}


Thank you,

Timm
Update method on renderman.renderman_type

Setting renderman_type to SKY sets the lamp type to 'HEMI' See renderman code

    if light_type in ['SKY', 'ENV']:
        lamp.type = 'HEMI'


This is not a bug.  bpy.ops.object.lamp_add(type='SUN') adds a lamp object of type 'SUN' named "Sun",  which is pretty easy to test.