injectify.structures.listify.__init__()   A
last analyzed

Complexity

Conditions 5

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 12
rs 9.3333
c 0
b 0
f 0
cc 5
nop 2
1
"""This module contains the data structures that power Injectify."""
2
3
from collections import UserList
4
from typing import Sequence
5
6
7
class listify(UserList):
8
    """A ``list``-like object that wraps an object into a list if it is not
9
    a sequence, or converts the object to a list if it is a sequence."""
10
11
    def __init__(self, initlist):
12
        self.data = []
13
14
        if initlist is not None:
15
            if isinstance(initlist, list):
16
                self.data[:] = initlist
17
            elif isinstance(initlist, UserList):
18
                self.data[:] = initlist.data[:]
19
            elif isinstance(initlist, Sequence):
20
                self.data = list(initlist)
21
            else:
22
                self.data.append(initlist)
23