def inject_func_as_method(self, func, method_name=None, class_=None,
                          allow_override=False, allow_main=False,
                          verbose=True, override=None, force=False):
    if override is not None:
        allow_override = override
    if method_name is None:
        method_name = get_funcname(func)
    if force:
        allow_override = True
        allow_main = True
    old_method = getattr(self, method_name, None)
    new_method = func.__get__(self, self.__class__)
    if old_method is not None:
        old_im_func = get_method_func(old_method)
        new_im_func = get_method_func(new_method)
        if not allow_main and old_im_func is not None and (
                get_funcglobals(old_im_func)['__name__'] != '__main__' and
                get_funcglobals(new_im_func)['__name__'] == '__main__'):
            if True or VERBOSE_CLASS:
                print('[util_class] skipping re-inject of %r from __main__' % method_name)
            return
        if old_method is new_method or old_im_func is new_im_func:
            return
        elif allow_override is False:
            raise AssertionError(
                'Overrides are not allowed. Already have method_name=%r' %
                (method_name))
        elif allow_override == 'warn':
            print(
                'WARNING: Overrides are not allowed. Already have method_name=%r. Skipping' %
                (method_name))
            return
        elif allow_override == 'override+warn':
            print('WARNING: Overrides are allowed, but dangerous. method_name=%r.' %
                  (method_name))
            print('old_method = %r, im_func=%s' % (old_method, str(old_im_func)))
            print('new_method = %r, im_func=%s' % (new_method, str(new_im_func)))
            print(get_funcglobals(old_im_func)['__name__'])
            print(get_funcglobals(new_im_func)['__name__'])
        del old_method
    setattr(self, method_name, new_method)