Files
codeql/python/ql/src/Classes/WrongNumberArgumentsInClassInstantiation.qhelp
2018-11-19 15:10:42 +00:00

46 lines
1.9 KiB
XML

<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>
A call to the <code>__init__</code> method of a class must supply an argument
for each parameter that does not have a default value defined, so:
</p>
<ul>
<li>The minimum number of arguments is the number of parameters without default values.</li>
<li>The maximum number of arguments is the total number of parameters, unless
the class <code>__init__</code> method takes a varargs (starred) parameter in
which case there is no limit.</li>
</ul>
</overview>
<recommendation>
<p>If there are too few arguments then check to see which arguments have been omitted and supply values for those.</p>
<p>If there are too many arguments then check to see if any have been added by mistake and remove those.</p>
<p>
Also check where a comma has been inserted instead of an operator or a dot.
For example, the code is <code>obj,attr</code> when it should be <code>obj.attr</code>.
</p>
<p> If it is not clear which are the missing or surplus arguments, then this suggests a logical error.
The fix will then depend on the nature of the error.
</p>
</recommendation>
<example>
<sample src="WrongNumberArgumentsInClassInstantiation.py"/>
</example>
<references>
<li>Python Glossary: <a href="https://docs.python.org/2/glossary.html#term-argument">Arguments</a>.</li>
<li>Python Glossary: <a href="https://docs.python.org/glossary.html#term-parameter">Parameters</a>.</li>
<li>Python Programming FAQ: <a href="https://docs.python.org/2/faq/programming.html#faq-argument-vs-parameter">
What is the difference between arguments and parameters?</a>.</li>
<li>The Python Language Reference: <a href="https://docs.python.org/3/reference/datamodel.html#object.__init__">Data model: object.__init__</a></li>
<li>The Python Tutorial: <a href="https://docs.python.org/3/tutorial/classes.html">Classes</a></li>
</references>
</qhelp>