Reason why xrange is not inheritable in Python?


I was trying to inherit xrange (to implement membership testing with in, as well as iteration). But I got the following error message:

TypeError: Error when calling the metaclass bases
    type 'xrange' is not an acceptable base type

What’s special about xrange?

Asked By: Frozen Flame



xrange is implemented in C. As you can see in Tim Peters’ post, there should be a convincing use case in order to justify the extra effort needed to allow subclassing of it.

Answered By: Bach