Statistics
| Revision:

gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.app / org.gvsig.scripting.app.mainplugin / src / main / resources-plugin / scripting / lib / pylint / test / functional / super_checks.py @ 745

History | View | Annotate | Download (3.48 KB)

1
# pylint: disable=too-few-public-methods,import-error, no-absolute-import,missing-docstring, wrong-import-position,invalid-name
2
"""check use of super"""
3

    
4
from unknown import Missing
5

    
6
class Aaaa:  # <3.0:[old-style-class]
7
    """old style"""
8
    def hop(self):  # <3.0:[super-on-old-class]
9
        """hop"""
10
        super(Aaaa, self).hop() # >=3.0:[no-member]
11

    
12
    def __init__(self):  # <3.0:[super-on-old-class]
13
        super(Aaaa, self).__init__()
14

    
15
class NewAaaa(object):
16
    """old style"""
17
    def hop(self):
18
        """hop"""
19
        super(NewAaaa, self).hop() # [no-member]
20

    
21
    def __init__(self):
22
        super(Aaaa, self).__init__()  # [bad-super-call]
23

    
24
class Py3kAaaa(NewAaaa):
25
    """new style"""
26
    def __init__(self):
27
        super().__init__()  # <3.0:[missing-super-argument]
28

    
29
class Py3kWrongSuper(Py3kAaaa):
30
    """new style"""
31
    def __init__(self):
32
        super(NewAaaa, self).__init__()  # [bad-super-call]
33

    
34
class WrongNameRegression(Py3kAaaa):
35
    """ test a regression with the message """
36
    def __init__(self):
37
        super(Missing, self).__init__()  # [bad-super-call]
38

    
39
class Getattr(object):
40
    """ crash """
41
    name = NewAaaa
42

    
43
class CrashSuper(object):
44
    """ test a crash with this checker """
45
    def __init__(self):
46
        super(Getattr.name, self).__init__()  # [bad-super-call]
47

    
48
class Empty(object):
49
    """Just an empty class."""
50

    
51
class SuperDifferentScope(object):
52
    """Don'emit bad-super-call when the super call is in another scope.
53
    For reference, see https://bitbucket.org/logilab/pylint/issue/403.
54
    """
55
    @staticmethod
56
    def test():
57
        """Test that a bad-super-call is not emitted for this case."""
58
        class FalsePositive(Empty):
59
            """The following super is in another scope than `test`."""
60
            def __init__(self, arg):
61
                super(FalsePositive, self).__init__(arg)
62
        super(object, 1).__init__() # [bad-super-call]
63

    
64

    
65
class UnknownBases(Missing):
66
    """Don't emit if we don't know all the bases."""
67
    def __init__(self):
68
        super(UnknownBases, self).__init__()
69
        super(UnknownBases, self).test()
70
        super(Missing, self).test() # [bad-super-call]
71

    
72

    
73
# Test that we are detecting proper super errors.
74

    
75
class BaseClass(object):
76

    
77
    not_a_method = 42
78

    
79
    def function(self, param):
80
        return param + self.not_a_method
81

    
82
    def __getattr__(self, attr):
83
        return attr
84

    
85

    
86
class InvalidSuperChecks(BaseClass):
87

    
88
    def __init__(self):
89
        super(InvalidSuperChecks, self).not_a_method() # [not-callable]
90
        super(InvalidSuperChecks, self).attribute_error() # [no-member]
91
        super(InvalidSuperChecks, self).function(42)
92
        super(InvalidSuperChecks, self).function() # [no-value-for-parameter]
93
        super(InvalidSuperChecks, self).function(42, 24, 24) # [too-many-function-args]
94
        # +1: [unexpected-keyword-arg,no-value-for-parameter]
95
        super(InvalidSuperChecks, self).function(lala=42)
96
        # Even though BaseClass has a __getattr__, that won't
97
        # be called.
98
        super(InvalidSuperChecks, self).attribute_error() # [no-member]
99

    
100

    
101

    
102
# Regression for PyCQA/pylint/issues/773
103
import subprocess
104

    
105
# The problem was related to astroid not filtering statements
106
# at scope level properly, basically not doing strong updates.
107
try:
108
    TimeoutExpired = subprocess.TimeoutExpired
109
except AttributeError:
110
    class TimeoutExpired(subprocess.CalledProcessError):
111
        def __init__(self):
112
            returncode = -1
113
            self.timeout = -1
114
            super(TimeoutExpired, self).__init__(returncode)