-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathReturnValueIgnored.qhelp
45 lines (33 loc) · 1.5 KB
/
ReturnValueIgnored.qhelp
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
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>When a function returns a non-trivial value, that value should not be ignored. Doing so may result in errors being ignored or
information being thrown away.</p>
<p>A return value is considered to be trivial if it is <code>None</code> or it is a parameter (parameters, usually <code>self</code> are often
returned to assist with method chaining, but can be ignored).
A return value is also assumed to be trivial if it is ignored for more than 25% of calls.
</p>
</overview>
<recommendation>
<p>Act upon all non-trivial return values, either propagating each value or recording it.
If a return value should be ignored, then ensure that it is ignored consistently.
</p>
<p>
If you have access to the source code of the called function, then consider modifying it so that it does not return pointless values.
</p>
</recommendation>
<example>
<p>
In the <code>ignore_error</code> function the error condition is ignored.
Ideally the <code>Resource.initialize()</code> function would raise an exception if it failed, but as it does not, the caller must deal with the error.
The <code>do_not_ignore_error</code> function checks the error condition and raises an exception if <code>Resource.initialize()</code> fails.
</p>
<sample src="ReturnValueIgnored.py" />
</example>
<references>
<li>Python Language Reference: <a href="http://docs.python.org/2/reference/compound_stmts.html#function">Function definitions</a>.
</li>
</references>
</qhelp>