mirror of
https://github.com/github/codeql.git
synced 2025-12-20 02:44:30 +01:00
28 lines
941 B
XML
28 lines
941 B
XML
<!DOCTYPE qhelp PUBLIC
|
|
"-//Semmle//qhelp//EN"
|
|
"qhelp.dtd">
|
|
<qhelp>
|
|
<overview>
|
|
<p> Subclass shadowing occurs when an instance attribute of a superclass has the
|
|
the same name as a method of a subclass, or vice-versa.
|
|
The semantics of Python attribute look-up mean that the instance attribute of
|
|
the superclass hides the method in the subclass.
|
|
</p>
|
|
|
|
</overview>
|
|
<recommendation>
|
|
|
|
<p>Rename the method in the subclass or rename the attribute in the superclass.</p>
|
|
|
|
</recommendation>
|
|
<example>
|
|
<p>The following code includes an example of subclass shadowing. When you call <code>Cow().milk()</code>
|
|
an error is raised because <code>Cow().milk</code> is interpreted as the 'milk' attribute set in
|
|
<code>Mammal.__init__</code>, not the 'milk' method defined within <code>Cow</code>. This can be fixed
|
|
by changing the name of either the 'milk' attribute or the 'milk' method.</p>
|
|
|
|
<sample src="SubclassShadowing.py" />
|
|
|
|
</example>
|
|
</qhelp>
|