summaryrefslogtreecommitdiff
path: root/pylint/test/functional/dangerous_default_value.py
blob: 58a22f443443ebee2e4a5c835dda571c113260fe (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
# pylint: disable=missing-docstring


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