blob: be3e96da32871b28fee942212c0dc58158bda632 (
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
"""Test for the invalid-name warning."""
import abc
import collections
GOOD_CONST_NAME = ''
bad_const_name = 0 # [invalid-name]
def BADFUNCTION_name(): # [invalid-name]
"""Bad function name."""
BAD_LOCAL_VAR = 1 # [invalid-name]
print BAD_LOCAL_VAR
def func_bad_argname(NOT_GOOD): # [invalid-name]
"""Function with a badly named argument."""
return NOT_GOOD
def no_nested_args(arg1, arg21, arg22):
"""Well-formed function."""
print arg1, arg21, arg22
class bad_class_name(object): # [invalid-name]
"""Class with a bad name."""
class CorrectClassName(object):
"""Class with a good name."""
def __init__(self):
self._good_private_name = 10
self.__good_real_private_name = 11
self.good_attribute_name = 12
self._Bad_AtTR_name = None # [invalid-name]
self.Bad_PUBLIC_name = None # [invalid-name]
zz = 'Bad Class Attribute' # [invalid-name]
GOOD_CLASS_ATTR = 'Good Class Attribute'
def BadMethodName(self): # [invalid-name]
"""A Method with a bad name."""
def good_method_name(self):
"""A method with a good name."""
def __DunDER_IS_not_free_for_all__(self): # [invalid-name]
"""Another badly named method."""
class DerivedFromCorrect(CorrectClassName):
"""A derived class with an invalid inherited members.
Derived attributes and methods with invalid names do not trigger warnings.
"""
zz = 'Now a good class attribute'
def __init__(self):
super(DerivedFromCorrect, self).__init__()
self._Bad_AtTR_name = None # Ignored
def BadMethodName(self):
"""Ignored since the method is in the interface."""
V = [WHAT_Ever_inListComp for WHAT_Ever_inListComp in GOOD_CONST_NAME]
def class_builder():
"""Function returning a class object."""
class EmbeddedClass(object):
"""Useless class."""
return EmbeddedClass
# +1:[invalid-name]
BAD_NAME_FOR_CLASS = collections.namedtuple('Named', ['tuple'])
NEXT_BAD_NAME_FOR_CLASS = class_builder() # [invalid-name]
GoodName = collections.namedtuple('Named', ['tuple'])
ToplevelClass = class_builder()
# Aliases for classes have the same name constraints.
AlsoCorrect = CorrectClassName
NOT_CORRECT = CorrectClassName # [invalid-name]
def test_globals():
"""Names in global statements are also checked."""
global NOT_CORRECT
global AlsoCorrect # [invalid-name]
NOT_CORRECT = 1
AlsoCorrect = 2
class FooClass(object):
"""A test case for property names.
Since by default, the regex for attributes is the same as the one
for method names, we check the warning messages to contain the
string 'attribute'.
"""
@property
def PROPERTY_NAME(self): # [invalid-name]
"""Ignored."""
pass
@abc.abstractproperty
def ABSTRACT_PROPERTY_NAME(self): # [invalid-name]
"""Ignored."""
pass
@PROPERTY_NAME.setter
def PROPERTY_NAME_SETTER(self): # [invalid-name]
"""Ignored."""
pass
|