From 6193629666c292d7cdaf10b0ccf018a4a700a84a Mon Sep 17 00:00:00 2001
From: "Jeroen F.J. Laros" <jlaros@fixedpoint.nl>
Date: Sun, 19 Apr 2015 13:59:21 +0200
Subject: [PATCH] Using composition instead of subclassing for the HGVSList
 class.

---
 mutalyzer/variant.py | 40 ++++++++++++++++++++++++++++++++--------
 1 file changed, 32 insertions(+), 8 deletions(-)

diff --git a/mutalyzer/variant.py b/mutalyzer/variant.py
index 5b84b3dc..fc3818d3 100644
--- a/mutalyzer/variant.py
+++ b/mutalyzer/variant.py
@@ -18,21 +18,41 @@ WEIGHTS = {
 }
 
 
-class HGVSList(list):
+class HGVSList(object):
     """
     Container for a list of sequences or variants.
     """
+    def __init__(self, items=[]):
+        self.items = list(items)
+
+
+    def __getitem__(self, index):
+        return self.items[index]
+
+
+    def __bool__(self):
+        return bool(len(self.items) > 0)
+
+
+    def __nonzero__(self): # Python 2.x compatibility.
+        return self.__bool__()
+
+
     def __unicode__(self):
-        if len(self) > 1:
-            return '[{}]'.format(';'.join(map(unicode, self)))
-        return unicode(self[0])
+        if len(self.items) > 1:
+            return '[{}]'.format(';'.join(map(unicode, self.items)))
+        return unicode(self.items[0])
+
+
+    def append(self, item):
+        self.items.append(item)
 
 
     def weight(self):
-        weight = sum(map(lambda x: x.weight(), self))
+        weight = sum(map(lambda x: x.weight(), self.items))
 
-        if len(self) > 1:
-            return weight + (len(self) + 1) * extractor.WEIGHT_SEPARATOR
+        if len(self.items) > 1:
+            return weight + (len(self.items) + 1) * extractor.WEIGHT_SEPARATOR
         return weight
 
 
@@ -82,10 +102,14 @@ class ISeq(object):
         return '{}_{}{}'.format(self.start, self.end, inverted)
 
 
-    def __nonzero__(self):
+    def __bool__(self):
          return bool(self.sequence)
 
 
+    def __nonzero__(self): # Python 2.x compatibility.
+        return self.__bool__()
+
+
     def weight(self):
         if self.type == 'ins':
             return len(self.sequence) * extractor.WEIGHT_BASE
-- 
GitLab