def sanitize_and_wrap(self, task_id, args, kwargs):
dep_failures = []<EOL>new_args = []<EOL>for dep in args:<EOL><INDENT>if isinstance(dep, Future):<EOL><INDENT>try:<EOL><INDENT>new_args.extend([dep.result()])<EOL><DEDENT>except Exception as e:<EOL><INDENT>if self.tasks[dep.tid]['<STR_LIT:status>'] in FINAL_FAILURE_STATES:<EOL><INDENT>dep_failures.extend([e])<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>new_args.extend([dep])<EOL><DEDENT><DEDENT>for key in kwargs:<EOL><INDENT>dep = kwargs[key]<EOL>if isinstance(dep, Future):<EOL><INDENT>try:<EOL><INDENT>kwargs[key] = dep.result()<EOL><DEDENT>except Exception as e:<EOL><INDENT>if self.tasks[dep.tid]['<STR_LIT:status>'] in FINAL_FAILURE_STATES:<EOL><INDENT>dep_failures.extend([e])<EOL><DEDENT><DEDENT><DEDENT><DEDENT>if '<STR_LIT>' in kwargs:<EOL><INDENT>new_inputs = []<EOL>for dep in kwargs['<STR_LIT>']:<EOL><INDENT>if isinstance(dep, Future):<EOL><INDENT>try:<EOL><INDENT>new_inputs.extend([dep.result()])<EOL><DEDENT>except Exception as e:<EOL><INDENT>if self.tasks[dep.tid]['<STR_LIT:status>'] in FINAL_FAILURE_STATES:<EOL><INDENT>dep_failures.extend([e])<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>new_inputs.extend([dep])<EOL><DEDENT><DEDENT>kwargs['<STR_LIT>'] = new_inputs<EOL><DEDENT>return new_args, kwargs, dep_failures<EOL>
This function should be called **ONLY** when all the futures we track have been resolved.

        If the user hid futures a level below, we will not catch
        it, and will (most likely) result in a type error.

        Args:
             task_id (uuid str) : Task id
             func (Function) : App function
             args (List) : Positional args to app function
             kwargs (Dict) : Kwargs to app function

        Return:
             partial function evaluated with all dependencies in  args, kwargs and kwargs['inputs'] evaluated.