Check parameter and return types for preloop and postloop hooks.
974442
def _validate_prepostloop_callable(cls, func: Callable[[None], None]) -> None:
        """"""
        cls._validate_callable_param_count(func, 0)
        # make sure there is no return notation
        signature = inspect.signature(func)
        if signature.return_annotation is not None:
            raise TypeError("{} must declare return a return type of 'None'".format(
                func.__name__,
            ))
1288941
def hook_outputs(modules:Collection[nn.Module], detach:bool=True, grad:bool=False)->Hooks:
    ""
    return Hooks(modules, _hook_inner, detach=detach, is_forward=not grad)
919348
def check_params_types(self, method):
        ''''''
        mn = method.__name__
        annos = dict(method.__annotations__)
        errors = []
        # Take a look at the syntax
        msg_tuple = 'Parameter {} in method {} is not annotated with a tuple.'
        msg_ptype = 'Parameter {} in method {} is not a valid Ptype.'
        msg_mod = 'Type for param {} in method {} must descend from Model.'
        msg_cls = 'Type for param {} in method {} must be instance (not class)'
        bodies = []
        for pname, anno in annos.items():
            if pname == 'return':
                continue
            elif len(anno) != 2:
                errors.append(msg_tuple.format(pname, mn))
            else:
                param_type, value_type = anno
                if param_type not in Ptypes:
                    errors.append(msg_ptype.format(pname, mn))
                elif param_type == 'body':
                    bodies.append(pname)
                elif param_type == 'path':
                    default = method.signature.parameters[pname].default
                    if default is not inspect._empty:
                        msg = ('Path prameter {} in method {} has a default '
                               'value ({}) that would make it optional (which '
                               'is wrong!)')
                        errors.append(msg.format(pname, mn, default))
                if hasattr(value_type, '__bases__'):
                    errors.append(msg_cls.format(pname, mn))
                elif Model not in value_type.__class__.__bases__:
                    errors.append(msg_mod.format(pname, mn))
        # Only one body parameter!
        if len(bodies) > 1:
            msg = 'Too many "Ptypes.body" params {} for method {} (max=1).'
            errors.append(msg.format(bodies, mn))
        return errors
316540
function addHook($type, $func, $prepend = false, $subtype = false)
    {
        if ($subtype)
        {
            if ($prepend)
            {
                array_unshift($this->hooks[$type][$subtype], $func);
            }
            else
            {
                $this->hooks[$type][$subtype][] = $func;
            }
        }
        else
        {
            if ($prepend)
            {
                array_unshift($this->hooks[$type], $func);
            }
            else
            {
                $this->hooks[$type][] = $func;
            }
        }
    }
78914
def check_preprocessor(self):
    """"""
    if _is_arraylike(self.preprocessor):
      self.preprocessor_ = ArrayIndexer(self.preprocessor)
    elif callable(self.preprocessor) or self.preprocessor is None:
      self.preprocessor_ = self.preprocessor
    else:
      raise ValueError("Invalid type for the preprocessor: {}. You should "
                       "provide either None, an array-like object, "
                       "or a callable.".format(type(self.preprocessor)))
502542
def determine_hooks(self, controller=None):
        '''
        
        '''

        controller_hooks = []
        if controller:
            controller_hooks = _cfg(controller).get('hooks', [])
            if controller_hooks:
                return list(
                    sorted(
                        chain(controller_hooks, self.hooks),
                        key=operator.attrgetter('priority')
                    )
                )
        return self.hooks
125420
def _check_type(self, check_type, properties):
        """"""
        if 'PrimitiveType' in properties:
            return properties['PrimitiveType'] == check_type
        if properties['Type'] == 'List':
            if 'ItemType' in properties:
                return properties['ItemType'] == check_type
            else:
                return properties['PrimitiveItemType'] == check_type
        return False
636064
def _monitor_callback_wrapper(callback):
    """"""
    def callback_handle(name, array, _):
        """ ctypes function """
        callback(name, array)
    return callback_handle
1052081
def _await_if_required(
        target: typing.Callable[..., typing.Union["typing.Awaitable[typing.Any]", typing.Any]]
    ) -> typing.Callable[..., typing.Any]:
        """"""

        @functools.wraps(target)
        def wrapper(*args, **kwargs):  # type: (typing.Any, typing.Any) -> typing.Any
            """Decorator/wrapper."""
            result = target(*args, **kwargs)
            if asyncio.iscoroutine(result):
                loop = asyncio.new_event_loop()
                result = loop.run_until_complete(result)
                loop.close()
            return result

        return wrapper
195517
static void checkTypes(ImmutableList<Type> types, Iterable<? extends Expression> exprs) {
    int size = Iterables.size(exprs);
    checkArgument(
        size == types.size(),
        "Supplied the wrong number of parameters. Expected %s, got %s",
        types.size(),
        size);
    // checkIsAssignableTo is an no-op if DEBUG is false
    if (Flags.DEBUG) {
      int i = 0;
      for (Expression expr : exprs) {
        expr.checkAssignableTo(types.get(i), "Parameter %s", i);
        i++;
      }
    }
  }
1088275
protected void checkNonGenericParameter(Method executeMethod, Parameter parameter) {
        if (isNonGenericCheckTargetType(parameter.getType())) { // e.g. List
            final Type paramedType = parameter.getParameterizedType();
            if (paramedType == null) { // no way? no check just in case
                return;
            }
            if (paramedType instanceof ParameterizedType) {
                final Type[] typeArgs = ((ParameterizedType) paramedType).getActualTypeArguments();
                if (typeArgs != null && typeArgs.length > 0 && "?".equals(typeArgs[0].getTypeName())) { // e.g. List<?>
                    throwActionFormWildcardOnlyListParameterException(executeMethod, parameter);
                }
            } else {
                throwActionFormNonGenericListParameterException(executeMethod, parameter);
            }
        }
    }
1371182
def postprocessor(accepts, flag=None):
    """"""
    def decorator(f):
        postprocessors.append((accepts, flag, f))
        return f
    return decorator
1273746
def _CollectTypeChecks(function, parent_type_check_dict, stack_location,
                      self_name):
  """"""
  type_check_dict = dict(parent_type_check_dict)
  type_check_dict.update(_ParseDocstring(function))

  # Convert any potential string based checks into python instances.
  for key, value in type_check_dict.items():
    if isinstance(value, str):
      type_check_dict[key] = _ParseTypeCheckString(value, stack_location + 1,
                                                  self_name)

  return type_check_dict
1037246
def uisetup(ui):
    """"""
    for hooktype in PREPOST_HOOKS:
        ui.setconfig("hooks", "pre-" + hooktype + ".autohooks", autohook)
        ui.setconfig("hooks", "post-" + hooktype + ".autohooks", autohook)
903780
def check_return_type(value, cllable = None, clss = None, caller_level = 0):
    
    return _check_caller_type(True, cllable, value, clss, caller_level+1)
728723
function getHook(className, hookType) {
  if (hooks[className] && hooks[className][hookType]) {
    return hooks[className][hookType];
  }
  return undefined;
}
355362
function(type, callback) {
        var list = this.__hooks[type] || [];
            list.push(callback);

        this.__hooks[type] = list;
    }