summaryrefslogtreecommitdiff
path: root/tests/functional/redefined_argument_from_local.py
blob: b1735e9c0aa80131d1fcf9596f78e98d63a2dd15 (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
# pylint: disable=missing-docstring, unused-variable, unused-argument
# pylint: disable=redefined-outer-name, invalid-name, redefine-in-handler

def test_redefined_in_with(name):
    with open('something') as name: # [redefined-argument-from-local]
        pass
    with open('something') as (second, name): # [redefined-argument-from-local]
        pass
    with open('something') as (second, (name, third)): # [redefined-argument-from-local]
        pass
    other = None
    with open('something') as other:
        pass



def test_not_redefined_in_with(name):
    with open('something') as test_redefined_in_with:
        pass



def test_redefined_in_for(name):
    for name in []: # [redefined-argument-from-local]
        pass
    for (name, is_) in []: # [redefined-argument-from-local]
        pass
    for (is_, (name, _)) in []: # [redefined-argument-from-local]
        pass
    for _ in []:
        pass


def test_not_redefined_in_for(name):
    for name_1 in []:
        pass

    # This one can be okay if you are interested in the last value
    # of the iteration
    other = None
    for other in []:
        pass


def test_redefined_in_except_handler(name):
    try:
        1 / 0
    except ZeroDivisionError as name: # [redefined-argument-from-local]
        pass


def test_not_redefined_in_except_handler(name):
    try:
        1 / 0
    except ZeroDivisionError as test_redefined_in_except_handler:
        pass


def test_not_redefined(name):
    if not name:
        name = ''


def apply_filter(objects, filt=lambda obj: True):
    for obj in objects:
        if filt(obj):
            yield obj