-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathExplicitReturnInInit.qhelp
More file actions
28 lines (23 loc) · 970 Bytes
/
ExplicitReturnInInit.qhelp
File metadata and controls
28 lines (23 loc) · 970 Bytes
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
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>The <code>__init__</code> method of a class is used to initialize new objects,
not create them. As such, it should not return any value. Returning <code>None</code>
is correct in the sense that no runtime error will occur,
but it suggests that the returned value is meaningful, which it is not.</p>
</overview>
<recommendation>
<p>Convert the <code>return expr</code> statement to a plain <code>return</code> statement,
or omit it altogether if it is at the end of the method.</p>
</recommendation>
<example>
<p>In this example, the <code>__init__</code> method attempts to return the newly created
object. This is an error and the return method should be removed.</p>
<sample src="ExplicitReturnInInit.py" />
</example>
<references>
<li>Python: <a href="http://docs.python.org/2.7/reference/datamodel.html#object.__init__">The __init__ method</a>.</li>
</references>
</qhelp>