summaryrefslogtreecommitdiff
path: root/tests/functional/s/self/self_cls_assignment.py
blob: 820531c618ff464051581b8fb410eacab0344068 (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
"""Warning about assigning self/cls variable."""
# pylint: disable=too-few-public-methods

class Foo:
    """Class with methods that check for self/cls assignment"""

    # pylint: disable=no-self-argument
    def self_foo(bar_):
        """Instance method, should warn for bar"""
        bar_ = 10  # [self-cls-assignment]

    def self_foofoo(self, lala):
        """Instance method, should warn for self"""
        self = lala  # [self-cls-assignment]
        self, var = lala, 1  # [self-cls-assignment]
        print(var)

    @classmethod
    def cls_foo(cls):
        """Class method, should warn for cls"""
        cls = 'tada'  # [self-cls-assignment]

    # pylint: disable=unused-argument
    @staticmethod
    def static_foo(lala):
        """Static method, no warnings"""
        lala = 10


# pylint: disable=unused-argument
def free_foo(bar_, lala):
    """Free function, no warnings"""
    bar_ = lala


class TestNonLocal:
    """Test class for nonlocal assignment of self"""

    def function(self, param):
        """This function uses nonlocal to reassign self"""

        def _set_param(param):
            nonlocal self
            self = param  # [self-cls-assignment]

        _set_param(param)
        return self