[issue37131] all(range()...)) is needlessley slow

2019-06-02 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: You can implement it yourself. _all = all def all(obj): if isinstance(obj, range): return 0 not in obj return _all(obj) I do not see reasons to do this in the stdlib. -- nosy: +serhiy.storchaka resolution: -> not a bug stage: -> r

[issue37131] all(range()...)) is needlessley slow

2019-06-02 Thread Steven D'Aprano
Steven D'Aprano added the comment: > >> Why should ``all()`` special case ``range``? Apart from showing off > >> benchmarks, what's the point? > > Mostly to avoid silly mistakes What sort of silly mistakes? > and the overhead of doing it would be very small, so a very small trade-off. Its

[issue37131] all(range()...)) is needlessley slow

2019-06-02 Thread Terji
Terji added the comment: >> If there were special dunders __all__ and __any__ it would be easy to >> encapsulate this behaviour inside the range objects themselves, and neither >> any() nor all() would need to know anything about range objects. This sounds very interesting, and more general.

[issue37131] all(range()...)) is needlessley slow

2019-06-02 Thread Terji
Terji added the comment: >> Why should ``all()`` special case ``range``? Apart from showing off >> benchmarks, what's the point? Mostly to avoid silly mistakes, and the overhead of doing it would be very small, so a very small trade-off. >> Should ``any()`` also special case it? No, ``any(

[issue37131] all(range()...)) is needlessley slow

2019-06-02 Thread Steven D'Aprano
Steven D'Aprano added the comment: Why should ``all()`` special case ``range``? Apart from showing off benchmarks, what's the point? Should ``any()`` also special case it? How about other lazy sequences and computed iterables, such as itertools.count objects, itertools.cycle objects, iterto

[issue37131] all(range()...)) is needlessley slow

2019-06-02 Thread Terji
New submission from Terji : Checking if a range's items are ll truthy can be done y checking if 0 the range contains 0, however currently Python iterates over the range, making the operation slower than needed. >>> rng = range(1, 1_000_000) >>> timeit all(rng) 19.9 ms ± 599 µs per