def METHOD_NAME(
    obj: Any, key: Text, default_value: Any
) -> Any:
  if isinstance(obj, Mapping):
    return obj.get(key, default_value)
  if getattr(obj, '_fields', None) is not None:
    return getattr(obj, key, default_value)
  return None