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.
Reason why xrange is not inheritable in Python?
Question
I was trying to inherit xrange
to enable the target object behaviors of an integer list (iterable and in
operator support). 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 of xrange
?
Also, probably not related to that question, I noticed xrange
has not method __contains__
. For in
operation, my basic knowledge is, a in A
is equivalent to A.contains(a). Am I wrong, or xrange
is something different?
I don't know if I should paste these as two separated questions. Appologize ahead.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow