为什么xrange在Python中不可继承?

Fro*_*ame 6 python inheritance xrange typeerror

我试图继承xrange(使用in以及迭代来实现成员资格测试)。但我收到以下错误消息:

TypeError: Error when calling the metaclass bases
    type 'xrange' is not an acceptable base type
Run Code Online (Sandbox Code Playgroud)

有什么特别之处xrange

Bac*_*ach 5

xrange在 C 中实现。正如您在Tim Peters 的文章中所看到的,应该有一个令人信服的用例来证明允许子类化所需的额外努力是合理的。