Fabian Peter Hammerle 7 years ago
parent
commit
b59ff475ec
1 changed files with 10 additions and 26 deletions
  1. 10 26
      dingguo/__init__.py

+ 10 - 26
dingguo/__init__.py

@@ -25,7 +25,15 @@ def yaml_construct_timestamp(loader, node):
     return loaded_dt
 yaml.Loader.add_constructor(u'tag:yaml.org,2002:timestamp', yaml_construct_timestamp)
 
-class _YamlInitConstructor(yaml.YAMLObject):
+class _Object(object):
+
+    def __eq__(self, other):
+        return type(self) == type(other) and vars(self) == vars(other)
+
+    def __ne__(self, other):
+        return not (self == other)
+
+class _YamlInitConstructor(_Object, yaml.YAMLObject):
 
     @classmethod
     def from_yaml(cls, loader, node):
@@ -35,9 +43,6 @@ class _YamlInitConstructor(yaml.YAMLObject):
         #         for (k, v) in loader.construct_mapping(node, deep = True).items()
         #     })
 
-    def __ne__(self, other):
-        return not (self == other)
-
 class Figure(_YamlInitConstructor):
 
     yaml_tag = u"!figure"
@@ -65,9 +70,6 @@ class Figure(_YamlInitConstructor):
     """ use property() instead of decorator to enable overriding """
     unit = property(get_unit, set_unit)
 
-    def __eq__(self, other):
-        return type(self) == type(other) and self.value == other.value and self.unit == other.unit
-
     @classmethod
     def to_yaml(cls, dumper, figure):
         return dumper.represent_mapping(
@@ -164,10 +166,6 @@ class Discount(_YamlInitConstructor):
         assert amount.value >= 0
         self.amount = amount
 
-    def __eq__(self, other):
-        return (type(self) == type(other)
-                and vars(self) == vars(other))
-
 class Order(_YamlInitConstructor):
 
     yaml_tag = u'!order'
@@ -203,10 +201,6 @@ class Order(_YamlInitConstructor):
             assert all([isinstance(d, Discount) for d in discounts])
             self.discounts = discounts
 
-    def __eq__(self, other):
-        return (type(self) == type(other)
-                and vars(self) == vars(other))
-
 class Item(_YamlInitConstructor):
 
     yaml_tag = u'!item'
@@ -221,10 +215,6 @@ class Item(_YamlInitConstructor):
         assert type(price_brutto) is Sum
         self.price_brutto = price_brutto
 
-    def __eq__(self, other):
-        return (type(self) == type(other)
-                and vars(self) == vars(other))
-
 class Article(Item):
 
     yaml_tag = u'!article'
@@ -361,7 +351,7 @@ class TaxiRide(Transportation):
         assert departure_time is None or type(departure_time) is datetime.datetime
         self.departure_time = departure_time
 
-class OrderRegistry(yaml.YAMLObject):
+class OrderRegistry(_Object, yaml.YAMLObject):
 
     yaml_tag = u'!order-registry'
 
@@ -384,9 +374,6 @@ class OrderRegistry(yaml.YAMLObject):
         self.registry = loader.construct_mapping(node)
         return self
 
-    def __eq__(self, other):
-        return type(self) == type(other) and vars(self) == vars(other)
-
 class Person(_YamlInitConstructor):
 
     yaml_tag = u'!person'
@@ -420,9 +407,6 @@ class Person(_YamlInitConstructor):
             'last_name': person.last_name,
             })
 
-    def __eq__(self, other):
-        return type(self) == type(other) and vars(self) == vars(other)
-
     def __repr__(self):
         return self.__class__.__name__ + '(%s)' % ', '.join([
             '%s=%r' % (k, v) for k, v in vars(self).items()