mirror of
https://github.com/github/codeql.git
synced 2026-02-14 14:11:20 +01:00
35 lines
1.2 KiB
XML
35 lines
1.2 KiB
XML
<!DOCTYPE qhelp PUBLIC
|
|
"-//Semmle//qhelp//EN"
|
|
"qhelp.dtd">
|
|
<qhelp>
|
|
|
|
|
|
<overview>
|
|
<p> Normal methods should have at least one parameter and the first parameter should be called <code>self</code>.
|
|
</p>
|
|
</overview>
|
|
|
|
<recommendation>
|
|
<p>Ensure that the first parameter of a normal method is named <code>self</code>, as recommended by the style guidelines
|
|
in PEP 8.</p>
|
|
<p>If a <code>self</code> parameter is unneeded, the method should be decorated with <code>staticmethod</code>, or moved out of the class as a regular function.
|
|
</p>
|
|
</recommendation>
|
|
|
|
<example>
|
|
<p>In the following cases, the first argument of <code>Point.__init__</code> is named <code>val</code> instead; whereas in <code>Point2.__init__</code> it is correctly named <code>self</code>.</p>
|
|
<sample src="NonSelf.py" />
|
|
|
|
|
|
</example>
|
|
<references>
|
|
|
|
<li>Python PEP 8: <a href="http://www.python.org/dev/peps/pep-0008/#function-and-method-arguments">Function and
|
|
method arguments</a>.</li>
|
|
<li>Python Tutorial: <a href="http://docs.python.org/2/tutorial/classes.html">Classes</a>.</li>
|
|
<li>Python Docs: <a href="https://docs.python.org/3/library/functions.html#staticmethod">staticmethod</a>.</li>
|
|
|
|
|
|
</references>
|
|
</qhelp>
|