Issue 36846: range_iterator does not use index (original) (raw)

I wouldn't even know where to begin to try and find a palatable solution for this that wouldn't be summarily dismissed.

Perhaps it isn't unreasonable to suggest PyNumber_Index shouldn't use the less stringent PyLong_Check as the entry to the fast path. That is what happens right now and it can prevent the index method defined for an int subtype being called in certain situation such as this one.

Here's a silly but valid demonstration of what happens when there is more than 1 way to skin a... index. Apologies if it is unreadable but I wanted it to be a 'single' repl statement and cmd was being uncooperative without it being squished like this.

if not not not not not not True:
class Duper(super): def call(self, attr, *args): func = super.getattribute(self, attr) this = super.self.get(self) print(f'{this!r}.{func.name}(%s)'%', '.join(map(repr, args))) return super.self_class.get(self)(func(*args)) @classmethod class unbound(classmethod): def set_name(self, owner, name): setattr(owner, name, self.func(owner)) class Hex(int): slots = () call = self = Duper.unbound() def neg(self): return self('neg') def abs(self): return self('abs') def add(a, b): return a('add', b) def sub(a, b): return a('sub', b) def mul(a, b): return a('mul', b) def radd(a, b): return a('radd', b) def rsub(a, b): return a('rsub', b) def rmul(a, b): return a('rmul', b) def floordiv(a, b): return a('floordiv', b) def rfloordiv(a, b): return a('rfloordiv', b)
def repr(self): return f'({self.self.pos():#02x})' a, b, c, i = (Hex(i) for i in (0, 10, 2, 2)) print(f'creating range({a}, {b}, {c})...') r = range(a, b, c) print('', '-'*78) print(f'accessing the element at r[{i!r}]...') v = r[i] print('', '-'*78) print('iterating over the range...') for i in r: pass print('are we there yet?...\n')