MutableList   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 50
rs 10
wmc 13

10 Methods

Rating   Name   Duplication   Size   Complexity  
A coerce() 0 12 3
A remove() 0 3 1
A insert() 0 3 1
A __getstate__() 0 2 1
A append() 0 3 1
A reverse() 0 3 1
A pop() 0 6 2
A extend() 0 3 1
A sort() 0 3 1
A __setstate__() 0 2 1
1
# -*- coding: utf-8 -*-
2
# based upon https://gist.github.com/eoghanmurray/1360da8635f0a6a6d528
3
from sqlalchemy.ext.mutable import Mutable
4
5
6
class MutableList(Mutable, list):
7
    @classmethod
8
    def coerce(cls, key, value):
9
        """
10
        Convert plain list to MutableList.
11
        """
12
        if not isinstance(value, MutableList):
13
            if isinstance(value, list):
14
                return MutableList(value)
15
            # this call will raise ValueError
16
            return Mutable.coerce(key, value)
17
        else:
18
            return value
19
20
    def __getstate__(self):
21
        return list(self)
22
23
    def __setstate__(self, state):
24
        self.extend(state)
25
26
    def append(self, value):
27
        list.append(self, value)
28
        self.changed()
29
30
    def extend(self, iterable):
31
        list.extend(self, iterable)
32
        self.changed()
33
34
    def insert(self, index, item):
35
        list.insert(self, index, item)
36
        self.changed()
37
38
    def pop(self, index=None):
39
        if index:
40
            list.pop(self, index)
41
        else:
42
            list.pop(self)
43
        self.changed()
44
45
    def remove(self, item):
46
        list.remove(self, item)
47
        self.changed()
48
49
    def reverse(self):
50
        list.reverse(self)
51
        self.changed()
52
53
    def sort(self, **kwargs):
54
        list.sort(self, **kwargs)
55
        self.changed()
56