I need two attributes of a class to either both be None
or both be an int
. There are already checks to make sure that if they are both set to something other than None, they will be ints. So at the end of the __init__
method I am calling a small function which checks if in either order, their types differ:
def both_none_or_both_something_else(a,b):
if a is None and b is not None:
return False
if b is None and a is not None:
return False
return True
>> both_none_or_both_something_else(5,None) # False
>> both_none_or_both_something_else(None,3) # False
>> both_none_or_both_something_else(5,20) # True
>> both_none_or_both_something_else(None, None) # True
Can this check of the two variables be condensed into a single line?