From a471c8b6939aeb5b7aa5d4aecab1c1db32989ea5 Mon Sep 17 00:00:00 2001 From: Alan Boudreault Date: Tue, 17 Jan 2017 16:24:33 -0500 Subject: [PATCH] no more validation required --- cassandra/cqltypes.py | 1 - cassandra/util.py | 19 ++----------------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/cassandra/cqltypes.py b/cassandra/cqltypes.py index 4eed45bf..6c155209 100644 --- a/cassandra/cqltypes.py +++ b/cassandra/cqltypes.py @@ -671,7 +671,6 @@ class DurationType(_CassandraType): @staticmethod def serialize(duration, protocol_version): try: - duration.validate() m, d, n = duration.months, duration.days, duration.nanoseconds except AttributeError: raise TypeError('DurationType arguments must be a Duration.') diff --git a/cassandra/util.py b/cassandra/util.py index f0fdca9f..924b5c79 100644 --- a/cassandra/util.py +++ b/cassandra/util.py @@ -1208,22 +1208,6 @@ class Duration(object): self.months = months self.days = days self.nanoseconds = nanoseconds - self.validate() - - def validate(self): - """ - A Duration is valid if its values are all positive or all negative. It cannot has mixed signs. - """ - if self._has_negative_values and self._has_positive_values: - raise ValueError('Duration values cannot have mixed signs.') - - @property - def _has_negative_values(self): - return self.months < 0 or self.days < 0 or self.nanoseconds < 0 - - @property - def _has_positive_values(self): - return self.months > 0 or self.days > 0 or self.nanoseconds > 0 def __eq__(self, other): return isinstance(other, self.__class__) and self.months == other.months and self.days == other.days and self.nanoseconds == other.nanoseconds @@ -1232,8 +1216,9 @@ class Duration(object): return "Duration({0}, {1}, {2})".format(self.months, self.days, self.nanoseconds) def __str__(self): + has_negative_values = self.months < 0 or self.days < 0 or self.nanoseconds < 0 return '%s%dmo%dd%dns' % ( - '-' if self._has_negative_values else '', + '-' if has_negative_values else '', abs(self.months), abs(self.days), abs(self.nanoseconds)