import functools
import inspect


def get_func_kwargs(func):
  """Get keyword args of a function."""
  # first, unwrap functools.partial. only extra keyword arguments.
  partial_supported_params = {}
  while isinstance(func, functools.partial):
    partial_supported_params.update(func.keywords)
    func = func.func
  # secondly, inspect the original function for keyword arguments.
  fn_params = inspect.signature(func).parameters
  support_kwargs = any(
      v.kind == inspect.Parameter.VAR_KEYWORD for v in fn_params.values())
  supported_params = {
      k: v.default
      for k, v in fn_params.items()
      if v.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD and
      v.default != inspect._empty
  }
  supported_params.update(partial_supported_params)
  return supported_params, support_kwargs