aboutsummaryrefslogtreecommitdiff
path: root/tests/functional/d/dangerous_default_value.py
blob: 161eaceed3f2798119c8a2849784490eb672807d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# pylint: disable=missing-docstring, use-list-literal, use-dict-literal
import collections

HEHE = {}

def function1(value=[]): # [dangerous-default-value]
    """docstring"""
    return value

def function2(value=HEHE): # [dangerous-default-value]
    """docstring"""
    return value

def function3(value):
    """docstring"""
    return value

def function4(value=set()): # [dangerous-default-value]
    """set is mutable and dangerous."""
    return value

def function5(value=frozenset()):
    """frozenset is immutable and safe."""
    return value

GLOBAL_SET = set()

def function6(value=GLOBAL_SET): # [dangerous-default-value]
    """set is mutable and dangerous."""
    return value

def function7(value=dict()): # [dangerous-default-value]
    """dict is mutable and dangerous."""
    return value

def function8(value=list()):  # [dangerous-default-value]
    """list is mutable and dangerous."""
    return value

def function9(value=[1, 2, 3, 4]): # [dangerous-default-value]
    """list with items should not output item values in error message"""
    return value

def function10(value={'a': 1, 'b': 2}): # [dangerous-default-value]
    """dictionaries with items should not output item values in error message"""
    return value

def function11(value=list([1, 2, 3])): # [dangerous-default-value]
    """list with items should not output item values in error message"""
    return value

def function12(value=dict([('a', 1), ('b', 2)])): # [dangerous-default-value]
    """dictionaries with items should not output item values in error message"""
    return value

OINK = {
    'a': 1,
    'b': 2
}

def function13(value=OINK): # [dangerous-default-value]
    """dictionaries with items should not output item values in error message"""
    return value

def function14(value=dict([(1, 2), (1, 2, 3)])): # [dangerous-default-value]
    """a dictionary which will not be inferred to a syntax AST, but to an
    astroid.Instance.
    """
    return value

INVALID_DICT = dict([(1, 2), (1, 2, 3)])

def function15(value=INVALID_DICT): # [dangerous-default-value]
    """The same situation as function14."""
    return value

def function16(value={1}): # [dangerous-default-value]
    """set literal as default value"""
    return value

def function17(value=collections.deque()):  # [dangerous-default-value]
    """mutable, dangerous"""
    return value

def function18(value=collections.ChainMap()):  # [dangerous-default-value]
    """mutable, dangerous"""
    return value

def function19(value=collections.Counter()):  # [dangerous-default-value]
    """mutable, dangerous"""
    return value

def function20(value=collections.OrderedDict()):  # [dangerous-default-value]
    """mutable, dangerous"""
    return value

def function21(value=collections.defaultdict()):  # [dangerous-default-value]
    """mutable, dangerous"""
    return value

def function22(value=collections.UserDict()):  # [dangerous-default-value]
    """mutable, dangerous"""
    return value

def function23(value=collections.UserList()):  # [dangerous-default-value]
    """mutable, dangerous"""
    return value

def function24(*, value=[]): # [dangerous-default-value]
    """dangerous default value in kwarg."""
    return value