mirror of
https://github.com/github/codeql.git
synced 2025-12-24 12:46:34 +01:00
31 lines
1.2 KiB
XML
31 lines
1.2 KiB
XML
<!DOCTYPE qhelp PUBLIC
|
|
"-//Semmle//qhelp//EN"
|
|
"qhelp.dtd">
|
|
<qhelp>
|
|
<overview>
|
|
<p>Python 2.3 introduced new-style classes (classes inheriting from object). New-style classes use
|
|
the C3 linearization method to determine a method resolution ordering (MRO) for each class. The C3
|
|
linearization method ensures that for a class C, if a class C1 precedes a class C2 in the MRO of C
|
|
then C1 should also precede C2 in the MRO of all subclasses of C. It is possible to create a
|
|
situation where it is impossible to achieve this consistency and this will guarantee that a <code>
|
|
TypeError</code> will be raised at runtime.</p>
|
|
|
|
</overview>
|
|
<recommendation>
|
|
<p>Use a class hierarchy that is not ambiguous.</p>
|
|
|
|
</recommendation>
|
|
<example>
|
|
<p>The MRO of class <code>X</code> is just <code>X, object</code>. The program will fail when the MRO
|
|
of class <code>Y</code> needs to be calculated because <code>object</code> precedes <code>X</code> in
|
|
the definition of <code>Y</code> but the opposite is true in the MRO of <code>X</code>.</p>
|
|
<sample src="InconsistentMRO.py" />
|
|
|
|
</example>
|
|
<references>
|
|
|
|
<li>Python: <a href="http://www.python.org/download/releases/2.3/mro/">The Python 2.3 Method Resolution Order</a>.</li>
|
|
|
|
</references>
|
|
</qhelp>
|