| Total Complexity | 13 |
| Total Lines | 50 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # -*- coding: utf-8 -*- |
||
| 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 |