-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathuselesscode_test.py
More file actions
128 lines (103 loc) · 2.17 KB
/
uselesscode_test.py
File metadata and controls
128 lines (103 loc) · 2.17 KB
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
#Multiple declarations
def mult(a):
x = 1
y = a
x = 2
#Need to use x, otherwise it is ignored
#(The UnusedLocalVariable query will pick it up)
return x
def unique():
pass
def mult(x,y):
pass
#OK for multiple definition
import M
M = none
def _double_loop(seq):
for i in seq:
pass
for i in seq:
pass
class Mult(object):
pass
class C(object):
def m(self):
pass
class Mult(object):
pass
### Tests inspired by real-world false positives
def isStr(s):
ok = ''
try:
ok += s
except TypeError:
return 0
return 1
# 'bad' actually *is* always redefined before being read.
def have_nosmp():
try:
bad = os.environ['NPY_NOSMP']
bad = 1
except KeyError:
bad = 0
return bad
def simple_try(foo):
try:
ok = foo.bar
except AttributeError:
ok = 'default'
return ok
def try_with_else(foo):
try:
bad = foo.bar
except AttributeError:
raise
else:
bad = 'overwrite'
return bad
# This should be fine
def append_all(xs):
global __doc__
__doc__ += "all xs:"
for x in xs:
__doc__ += x
def append_local(xs):
doc = ""
doc += "xs:"
for x in xs:
doc += x
return doc
#ODASA-4100
def odasa4100(name, language, options = ''):
distro_files = []
if language == 'distro-cpp':
distro_files = [ "file" ]
if distro_files:
emit_odasa_deps()
#Flow-graph splitting will make this definition unused on the distro_files is True branch
env = ''
if distro_files:
env = 'env "ODASA_HOME=' + _top + '/' + distro_path + '" '
emit_cmd(env + "some other stuff")
#ODASA-4166
#This is OK as the first definition is a "declaration"
def odasa4166(cond):
x = None
if cond:
x = some_value()
else:
x = default_value()
return x
#ODASA-5315
def odasa5315():
x, y = foo() # OK as y is used
use(y)
x, y = bar() # Not OK as neither x nor y are used.
x, y = baz() # OK as both used
return x + y
@multimethod(int)
def foo(i):
pass
@multimethod(float)
def foo(f):
pass