forked from PyCQA/pep8-naming
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
N806.py
171 lines (167 loc) · 2.8 KB
/
N806.py
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#: Okay
def test():
good = 1
#: Okay
def test():
def test2():
good = 1
#: Okay
GOOD = 1
#: Okay
class Test(object):
GOOD = 1
#: N806
def test():
Bad = 1
#: N806
def test():
VERY = 2
#: N806
def test():
def test2():
class Foo(object):
def test3(self):
Bad = 3
#: Okay(--ignore-names=Bad)
def test():
Bad = 1
#: Okay
def good():
global Bad
Bad = 1
#: N806
def bad():
global Bad
def foo():
Bad = 1
#: Okay
def test():
# namedtuples are often CamelCased since we treat them a bit like classes
import collections
Thing = collections.namedtuple('Thing', 'a b c')
from collections import namedtuple
ThingTwo = namedtuple('ThingTwo', 'a b c')
#: N806
def bad():
# Currently don't support aliased imports of namedtuple
from collections import namedtuple as nt
Thing = nt('Thing', 'a b c')
#: N806
def unpacking_into_tuple():
Var1, Var2 = range(2)
#: Okay
def unpacking_into_tuple():
var1, var2 = range(2)
#: N806
def unpacking_into_list():
[Var1, Var2] = range(2)
#: Okay
def unpacking_into_list():
[var1, var2] = range(2)
#: Okay
a, [b, c] = [1, [2, 3]]
#: N806
def recursive_unpack():
a, [bB, c] = [1, [2, 3]]
#: Okay
def assingnment_to_attribute():
a.b = 1
#: N806
def f():
with Foo(), Bar() as Bad:
pass
#: Okay
def f():
with FOO() as foo, bar() as bar:
pass
#: Okay
def f():
with suppress(E):
pass
with contextlib.suppress(E):
pass
#: Okay
with Test() as bar:
pass
#: N806
def f():
with Test() as BAD:
pass
#: Okay
def f():
with C() as [a, b, c]:
pass
#: N806
def f():
with C() as [a, Bad, c]:
pass
#: N806
def f():
with C() as (a, b, baD):
pass
#: Okay
def f():
for i in iterator:
pass
#: N806:2:9
def f():
for Bad in iterator:
pass
#: Okay
def f():
for a, b in enumerate(iterator):
pass
#: N806
def f():
for index, ITEM in enumerate(iterator):
pass
#: N806
def f():
try:
f()
except Exception as Bad:
pass
#: Okay
def f():
try:
f()
except Exception as good:
pass
#: Okay
def f():
try:
f()
except:
pass
#: Okay
def f():
try:
f()
except good:
pass
#: N806
def f():
try:
f()
except RuntimeError as good:
pass
except IndexError as BAD:
pass
#: Okay
def f():
return [i for i in range(3)]
#: N806:2:22
def t():
return [ITEM for ITEM in range(3)]
#: N806:2:24
def d():
return {AA: BB for AA, BB in {}}
#: N806:2:22
def s():
return {Item for Item in range(3)}
#: N806:2:57
def n():
return (good + BAD for good in range(3) if good for BAD in range(3) if BAD)
#: N806:2:26
def e():
return tuple(BaD for BaD in range(2))