summaryrefslogtreecommitdiff
path: root/pylint/test/input/func_noerror_access_attr_before_def_false_positive.py
blob: 8c285998dff54d97a4b5ba49a9623d8f57e03e57 (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
#pylint: disable=C0103,R0904,R0903,W0201,old-style-class,print-statement,no-absolute-import
"""
This module demonstrates a possible problem of pyLint with calling __init__ s
from inherited classes.
Initializations done there are not considered, which results in Error E0203 for
self.cookedq.
"""

__revision__ = 'yo'

import telnetlib

class SeeTelnet(telnetlib.Telnet):
    """
    Extension of telnetlib.
    """

    def __init__(self, host=None, port=0):
        """
        Constructor.
        When called without arguments, create an unconnected instance.
        With a hostname argument, it connects the instance; a port
        number is optional.
        Parameter:
        - host: IP address of the host
        - port: Port number
        """
        telnetlib.Telnet.__init__(self, host, port)

    def readUntilArray(self, matches, _=None):
        """
        Read until a given string is encountered or until timeout.
        ...
        """
        self.process_rawq()
        maxLength = 0
        for match in matches:
            if len(match) > maxLength:
                maxLength = len(match)

class Base(object):
    """bla bla"""
    dougloup_papa = None

    def __init__(self):
        self._var = False

class Derived(Base):
    """derived blabla"""
    dougloup_moi = None
    def Work(self):
        """do something"""
        # E0203 - Access to member '_var' before its definition
        if self._var:
            print "True"
        else:
            print "False"
        self._var = True

        # E0203 - Access to member 'dougloup_papa' before its definition
        if self.dougloup_papa:
            print 'dougloup !'
        self.dougloup_papa = True
        # E0203 - Access to member 'dougloup_moi' before its definition
        if self.dougloup_moi:
            print 'dougloup !'
        self.dougloup_moi = True


class QoSALConnection(object):
    """blabla"""

    _the_instance = None

    def __new__(cls):
        if cls._the_instance is None:
            cls._the_instance = object.__new__(cls)
        return cls._the_instance

    def __init__(self):
        pass

class DefinedOutsideInit(object):
    """use_attr is seen as the method defining attr because its in
    first position
    """
    def __init__(self):
        self.reset()

    def use_attr(self):
        """use and set members"""
        if self.attr:
            print 'hop'
        self.attr = 10

    def reset(self):
        """reset members"""
        self.attr = 4