from typing import Dict
from typing import Any


def _setdefault(dictionary: Dict[str, Any], key: str,
                value: Any) -> Dict[str, Any]:
  """Sets the default value of `key` to `value` if necessary.

  Args:
    dictionary: the dictionary to add a default for.
    key: The key to add a default for.
    value: The default value to add if key is missing.

  Returns:
    Either dictionary or a copy wiht the default value added.
  """
  if key in dictionary:
    return dictionary
  else:
    return dict(dictionary, **{key: value})