1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 MERGE_FAILURE_REASON = (
6 'Merging values containing a None value results in a None value.')
8 class NoneValueMissingReason(Exception):
11 class ValueMustHaveNoneValue(Exception):
14 def ValidateNoneValueReason(value, none_value_reason):
15 """Ensures that the none_value_reason is appropriate for the given value.
17 There is a logical equality between having a value of None and having a
18 reason for being None. That is to say, value is None if and only if
19 none_value_reason is a string.
21 if value is None and not isinstance(none_value_reason, basestring):
22 raise NoneValueMissingReason()
23 if value is not None and none_value_reason is not None:
24 raise ValueMustHaveNoneValue()