Skip to content

Commit 40c2be0

Browse files
authored
Merge pull request #10730: [BEAM-7746] Remove use of @functools.total_ordering
2 parents 51e47a3 + 7c9c2b0 commit 40c2be0

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

sdks/python/apache_beam/utils/timestamp.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from __future__ import division
2727

2828
import datetime
29-
import functools
3029
import time
3130
from builtins import object
3231
from typing import Any
@@ -45,9 +44,9 @@
4544
TimestampTypes = Union[int, float, 'Timestamp']
4645
# types compatible with Duration.of()
4746
DurationTypes = Union[int, float, 'Duration']
47+
TimestampDurationTypes = Union[int, float, 'Duration', 'Timestamp']
4848

4949

50-
@functools.total_ordering
5150
class Timestamp(object):
5251
"""Represents a Unix second timestamp with microsecond granularity.
5352
@@ -191,7 +190,7 @@ def __int__(self):
191190
return self.micros // 1000000
192191

193192
def __eq__(self, other):
194-
# type: (Union[int, float, Timestamp, Duration]) -> bool
193+
# type: (TimestampDurationTypes) -> bool
195194
# Allow comparisons between Duration and Timestamp values.
196195
if not isinstance(other, Duration):
197196
try:
@@ -206,12 +205,24 @@ def __ne__(self, other):
206205
return not self == other
207206

208207
def __lt__(self, other):
209-
# type: (Union[int, float, Timestamp, Duration]) -> bool
208+
# type: (TimestampDurationTypes) -> bool
210209
# Allow comparisons between Duration and Timestamp values.
211210
if not isinstance(other, Duration):
212211
other = Timestamp.of(other)
213212
return self.micros < other.micros
214213

214+
def __gt__(self, other):
215+
# type: (TimestampDurationTypes) -> bool
216+
return not (self < other or self == other)
217+
218+
def __le__(self, other):
219+
# type: (TimestampDurationTypes) -> bool
220+
return self < other or self == other
221+
222+
def __ge__(self, other):
223+
# type: (TimestampDurationTypes) -> bool
224+
return not self < other
225+
215226
def __hash__(self):
216227
return hash(self.micros)
217228

@@ -252,7 +263,6 @@ def __mod__(self, other):
252263
common_urns.constants.MAX_TIMESTAMP_MILLIS.constant)*1000)
253264

254265

255-
@functools.total_ordering
256266
class Duration(object):
257267
"""Represents a second duration with microsecond granularity.
258268
@@ -344,12 +354,24 @@ def __ne__(self, other):
344354
return not self == other
345355

346356
def __lt__(self, other):
347-
# type: (Union[int, float, Duration, Timestamp]) -> bool
357+
# type: (TimestampDurationTypes) -> bool
348358
# Allow comparisons between Duration and Timestamp values.
349359
if not isinstance(other, Timestamp):
350360
other = Duration.of(other)
351361
return self.micros < other.micros
352362

363+
def __gt__(self, other):
364+
# type: (TimestampDurationTypes) -> bool
365+
return not (self < other or self == other)
366+
367+
def __le__(self, other):
368+
# type: (TimestampDurationTypes) -> bool
369+
return self < other or self == other
370+
371+
def __ge__(self, other):
372+
# type: (TimestampDurationTypes) -> bool
373+
return not self < other
374+
353375
def __hash__(self):
354376
return hash(self.micros)
355377

0 commit comments

Comments
 (0)