human
Here's a good function header given the following:
I wrote the below code

    @functools.wraps(function)
    def decorated_function(self, context, *args, **kwargs):
        def _load_instance(instance_or_dict):
            if isinstance(instance_or_dict, dict):
                metas = [meta for meta in ('metadata', 'system_metadata') if (meta in instance_or_dict)]
                instance = objects.Instance._from_db_object(context, objects.Instance(), instance_or_dict, expected_attrs=metas)
                instance._context = context
                return instance
            return instance_or_dict
        try:
            kwargs['instance'] = _load_instance(kwargs['instance'])
        except KeyError:
            args = ((_load_instance(args[0]),) + args[1:])
        migration = kwargs.get('migration')
        if isinstance(migration, dict):
            migration = objects.Migration._from_db_object(context.elevated(), objects.Migration(), migration)
            kwargs['migration'] = migration
        return function(self, context, *args, **kwargs)
    return decorated_function

What's a good function header?
assistant
#Here's a good function header.

def object_compat(function):