def _set_widget_id(widget_type, element, user_key=None):
    "Set the widget id.\n\n    Parameters\n    ----------\n    widget_type : str\n        The type of the widget as stored in proto.\n    element : proto\n        The proto of the element\n    user_key : str\n        Optional user-specified key to use for the widget ID.\n        If this is None, we'll generate an ID by hashing the element.\n\n    "
    element_hash = hash(element.SerializeToString())
    if (user_key is not None):
        widget_id = ('%s-%s' % (user_key, element_hash))
    else:
        widget_id = ('%s' % element_hash)
    ctx = get_report_ctx()
    if (ctx is not None):
        added = ctx.widget_ids_this_run.add(widget_id)
        if (not added):
            raise DuplicateWidgetID(_build_duplicate_widget_message(widget_type, user_key))
    el = getattr(element, widget_type)
    el.id = widget_id
Set the widget id.

Parameters
----------
widget_type : str
    The type of the widget as stored in proto.
element : proto
    The proto of the element
user_key : str
    Optional user-specified key to use for the widget ID.
    If this is None, we'll generate an ID by hashing the element.
def _set_widget_id(widget_type, element, user_key=None):
    "Set the widget id.\n\n    Parameters\n    ----------\n    widget_type : str\n        The type of the widget as stored in proto.\n    element : proto\n        The proto of the element\n    user_key : str\n        Optional user-specified key to use for the widget ID.\n        If this is None, we'll generate an ID by hashing the element.\n\n    "
    element_hash = hash(element.SerializeToString())
    if (user_key is not None):
        widget_id = ('%s-%s' % (user_key, element_hash))
    else:
        widget_id = ('%s' % element_hash)
    ctx = get_report_ctx()
    if (ctx is not None):
        added = ctx.widget_ids_this_run.add(widget_id)
        if (not added):
            raise DuplicateWidgetID(_build_duplicate_widget_message(widget_type, user_key))
    el = getattr(element, widget_type)
    el.id = widget_id