Browse Source

Merge branch 'bugfix' of arys/pyTCore into master

Randy Paredis 2 years ago
parent
commit
c110ccc19b
1 changed files with 11 additions and 13 deletions
  1. 11 13
      util/infinity.py

+ 11 - 13
util/infinity.py

@@ -1,17 +1,16 @@
-# -*- coding: Latin-1 -*-
 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
 ## ##
-# infinity.py   
+# infinity.py
 #                     --------------------------------
 #                            Copyright (c) 2005
 #                          Jean-Sébastien  BOLDUC
-#                             Hans  Vangheluwe
+#                             Hans Vangheluwe
 #                       McGill University (Montréal)
 #                     --------------------------------
 #
-#  - Singleton class "Inf" and unique instance "INFINITY" --- 
+#  - Singleton class "Inf" and unique instance "INFINITY" ---
 #    stands for infinity (to use in time advance function)
-#    
+#
 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
 ## ##
 
@@ -22,13 +21,12 @@
 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
 ## ##
 
-class Infty(object):
+class Infinity:
     """Singleton class: the single instance "INFINITY" stands for infinity."""
-    __instantiated = False
-    def __init__(self):
-        if self.__instantiated:
-            raise NotImplementedError("singleton class already instantiated")
-        self.__instantiatiated = True
+    def __new__(cls):
+        if not hasattr(cls, "instance"):
+            cls.instance = super(Infinity, cls).__new__(cls)
+        return cls.instance
 
     def __deepcopy__(self, memo):
         return self
@@ -104,6 +102,6 @@ class Infty(object):
     def __str__(self):
         return "+INFINITY"
 
-# Instantiate singleton:    
-INFINITY = Infty()
 
+# Instantiate singleton:
+INFINITY = Infinity()