mirror of
https://github.com/github/codeql.git
synced 2025-12-18 01:33:15 +01:00
39 lines
1.2 KiB
XML
39 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>.
|
|
This makes the purpose of the parameter clear to other developers.
|
|
</p>
|
|
</overview>
|
|
|
|
<recommendation>
|
|
<p>If there is at least one parameter, then change the name of the first parameter to <code>self</code> as recommended by the style guidelines
|
|
in PEP 8.</p>
|
|
<p>If there are no parameters, then it cannot be a normal method. It may need to be marked as a <code>staticmethod</code>
|
|
or it could be moved out of the class as a normal function.
|
|
</p>
|
|
</recommendation>
|
|
|
|
<example>
|
|
<p>The following methods can both be used to assign values to variables in a <code>point</code>
|
|
object. The second method makes the association clearer because the <code>self</code> parameter is
|
|
used.</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>
|
|
|
|
|
|
|
|
</references>
|
|
</qhelp>
|