code: def partial_kwargs(
      function: Callable[..., Any], **kwargs: Any
  ) -> Callable[..., Any]:
      """Return a partial function application by overriding default keywords.
  
      This function is equivalent to `functools.partial(function, **kwargs)` but
      will raise a `ValueError` when called if either the given keyword arguments
      are not defined by `function` or if they do not have defaults.
  
      This is useful as a way to define a factory function with default parameters
      and then to override them in a safe way.
  
      Args:
        function: the base function before partial application.
        **kwargs: keyword argument overrides.
  
      Returns:
        A function.
      """
      # Try to get the argspec of our function which we'll use to get which keywords
      # have defaults.
      argspec = inspect.getfullargspec(function)
  
      # Figure out which keywords have defaults.
      if argspec.defaults is None:
          defaults = []
      else:
          defaults = argspec.args[-len(argspec.defaults) :]
  
      # Find any keys not given as defaults by the function.
      unknown_kwargs = set(kwargs.keys()).difference(defaults)
  
      # Raise an error
      if unknown_kwargs:
          error_string = (
              "Cannot override unknown or non-default kwargs: {}"
          )
          raise ValueError(
              error_string.format(", ".join(unknown_kwargs))
          )
  
      return functools.partial(function, **kwargs)
  
file_path: acme/acme/utils/lp_utils.py
imports: import atexit
  import functools
  import inspect
  import os
  import sys
  import time
  from typing import Any, Callable, Optional
  from absl import flags
  from absl import logging
  from acme.utils import counting
  from acme.utils import signals
label_desc: Use image node_id 1 for calling a global function with example usage: partial_kwargs(function) and returns: functools