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 / too_many_nested_blocks.py @ 745
History | View | Annotate | Download (2.21 KB)
1 |
"""Checks the maximum block level is smaller than 6 in function definitions"""
|
---|---|
2 |
|
3 |
#pylint: disable=using-constant-test, missing-docstring, too-many-return-statements
|
4 |
|
5 |
def my_function(): |
6 |
if 1: # [too-many-nested-blocks] |
7 |
for i in range(10): |
8 |
if i == 2: |
9 |
while True: |
10 |
try:
|
11 |
if True: |
12 |
i += 1
|
13 |
except IOError: |
14 |
pass
|
15 |
|
16 |
if 1: |
17 |
for i in range(10): |
18 |
if i == 2: |
19 |
while True: |
20 |
try:
|
21 |
i += 1
|
22 |
except IOError: |
23 |
pass
|
24 |
|
25 |
def nested_func(): |
26 |
if True: |
27 |
for i in range(10): |
28 |
while True: |
29 |
if True: |
30 |
if True: |
31 |
yield i
|
32 |
|
33 |
nested_func() |
34 |
|
35 |
def more_complex_function(): |
36 |
attr1 = attr2 = attr3 = [1, 2, 3] |
37 |
if attr1:
|
38 |
for i in attr1: |
39 |
if attr2:
|
40 |
return i
|
41 |
else:
|
42 |
return 'duh' |
43 |
elif attr2:
|
44 |
for i in attr2: |
45 |
if attr2:
|
46 |
return i
|
47 |
else:
|
48 |
return 'duh' |
49 |
else:
|
50 |
for i in range(15): |
51 |
if attr3:
|
52 |
return i
|
53 |
else:
|
54 |
return 'doh' |
55 |
return None |
56 |
|
57 |
def elif_function(): |
58 |
arg = None
|
59 |
if arg == 1: |
60 |
return 1 |
61 |
elif arg == 2: |
62 |
return 2 |
63 |
elif arg == 3: |
64 |
return 3 |
65 |
elif arg == 4: |
66 |
return 4 |
67 |
elif arg == 5: |
68 |
return 5 |
69 |
elif arg == 6: |
70 |
return 6 |
71 |
elif arg == 7: |
72 |
return 7 |
73 |
|
74 |
def else_if_function(): |
75 |
arg = None
|
76 |
if arg == 1: # [too-many-nested-blocks] |
77 |
return 1 |
78 |
else:
|
79 |
if arg == 2: |
80 |
return 2 |
81 |
else:
|
82 |
if arg == 3: |
83 |
return 3 |
84 |
else:
|
85 |
if arg == 4: |
86 |
return 4 |
87 |
else:
|
88 |
if arg == 5: |
89 |
return 5 |
90 |
else:
|
91 |
if arg == 6: |
92 |
return 6 |
93 |
else:
|
94 |
if arg == 7: |
95 |
return 7 |