<p>不,你不能。<code>super()</code>调用需要知道该方法是哪个类的一部分,以便在基类中搜索重写的方法。</p>
<p>如果您传入<code>self.__class__</code>(或者更好的方法是<code>type(self)</code>),那么<code>super()</code>就被赋予了搜索方法的<em>错误的</em>起点,并且最终将再次调用<em>它自己的方法</em>。</p>
<p>在构成方法解析顺序序列的类列表中将其视为指针。如果传入<code>type(self)</code>,则指针将引用任何子类,而不是原始起点。</p>
<p>以下代码导致无限递归错误:</p>
<pre><code>class Base(object):
def method(self):
print 'original'
class Derived(Base):
def method(self):
print 'derived'
super(type(self), self).method()
class Subclass(Derived):
def method(self):
print 'subclass of derived'
super(Subclass, self).method()
</code></pre>
<p>演示:</p>
<pre><code>>>> Subclass().method()
subclass of derived
derived
derived
derived
<... *many* lines removed ...>
File "<stdin>", line 4, in method
File "<stdin>", line 4, in method
File "<stdin>", line 4, in method
RuntimeError: maximum recursion depth exceeded while calling a Python object
</code></pre>
<p>因为<code>type(self)</code>是<code>Subclass</code>,<strong>不是</strong><code>Derived</code>,在<code>Derived.method()</code>。</p>
<p>在本例中,<code>Subclass</code>的MRO是<code>[Subclass, Derived, Base]</code>,并且<code>super()</code>需要知道从何处开始搜索任何重写的方法。通过使用<code>type(self)</code>你告诉它从<code>Subclass</code>开始,这样它就会找到<code>Derived.method()</code>下一个,这就是我们开始的地方。</p>