def _ref_obj_instance(self, obj):
    'Reference an existing object or flatten if new'
    if self.unpicklable:
        if self._mkref(obj):
            return self._flatten_obj_instance(obj)
        return self._getref(obj)
    else:
        max_reached = self._max_reached()
        in_cycle = _in_cycle(obj, self._objs, max_reached, False)
        if in_cycle:
            return None
        self._mkref(obj)
        return self._flatten_obj_instance(obj)
Reference an existing object or flatten if new
def _ref_obj_instance(self, obj):
    
    if self.unpicklable:
        if self._mkref(obj):
            return self._flatten_obj_instance(obj)
        return self._getref(obj)
    else:
        max_reached = self._max_reached()
        in_cycle = _in_cycle(obj, self._objs, max_reached, False)
        if in_cycle:
            return None
        self._mkref(obj)
        return self._flatten_obj_instance(obj)