From 11caa8a18addc72ce67ff4ea1f155caa39fac490 Mon Sep 17 00:00:00 2001 From: Joel Bender Date: Sun, 9 Aug 2015 23:26:03 -0400 Subject: [PATCH] add __lt__ function to make tasks orderable (so heappush is happy in py34), update metaclass syntax in py34 singleton --- py25/bacpypes/task.py | 3 +++ py27/bacpypes/task.py | 3 +++ py34/bacpypes/singleton.py | 10 +++++----- py34/bacpypes/task.py | 3 +++ tests/test_utilities/test_time_machine.py | 2 +- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/py25/bacpypes/task.py b/py25/bacpypes/task.py index b262cd8..e7c4d24 100755 --- a/py25/bacpypes/task.py +++ b/py25/bacpypes/task.py @@ -92,6 +92,9 @@ class _Task(DebugContents, Logging): _task_manager.resume_task(self) + def __lt__(self, other): + return id(self) < id(other) + # # OneShotTask # diff --git a/py27/bacpypes/task.py b/py27/bacpypes/task.py index af2407d..a9594c7 100755 --- a/py27/bacpypes/task.py +++ b/py27/bacpypes/task.py @@ -92,6 +92,9 @@ class _Task(DebugContents, Logging): _task_manager.resume_task(self) + def __lt__(self, other): + return id(self) < id(other) + # # OneShotTask # diff --git a/py34/bacpypes/singleton.py b/py34/bacpypes/singleton.py index 715f013..d08ae21 100755 --- a/py34/bacpypes/singleton.py +++ b/py34/bacpypes/singleton.py @@ -56,18 +56,18 @@ class _SingletonMetaclass(type): # Singleton # -class Singleton(object): +class Singleton(metaclass=_SingletonMetaclass): - __metaclass__ = _SingletonMetaclass + pass # # _SingletonLoggingMetaclass # class _SingletonLoggingMetaclass(_SingletonMetaclass, debugging._LoggingMetaclass): + pass -class SingletonLogging(object): - - __metaclass__ = _SingletonLoggingMetaclass +class SingletonLogging(metaclass=_SingletonLoggingMetaclass): + pass diff --git a/py34/bacpypes/task.py b/py34/bacpypes/task.py index af2407d..a9594c7 100755 --- a/py34/bacpypes/task.py +++ b/py34/bacpypes/task.py @@ -92,6 +92,9 @@ class _Task(DebugContents, Logging): _task_manager.resume_task(self) + def __lt__(self, other): + return id(self) < id(other) + # # OneShotTask # diff --git a/tests/test_utilities/test_time_machine.py b/tests/test_utilities/test_time_machine.py index f827edf..fcce5a2 100644 --- a/tests/test_utilities/test_time_machine.py +++ b/tests/test_utilities/test_time_machine.py @@ -203,4 +203,4 @@ class TestTimeMachine(unittest.TestCase): # function called, no time has passed assert ft1.process_task_called == 4 assert ft2.process_task_called == 3 - assert time_machine.current_time == 5.0 \ No newline at end of file + assert time_machine.current_time == 5.0