-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Closed as not planned
Closed as not planned
Copy link
Labels
Description
Feature or enhancement
Proposal:
Currently only itertools.chain
can be subscripted at runtime. I think most of other iterators should be subscriptable too.
Most of these classes are generic in typeshed, so typecheckers thing that subscripting them is fine, which is inconsistent with behaviour at runtime.
With pyright:
import itertools
x = itertools.cycle[str]('abc')
reveal_type(x) # cycle[str]
At runtime:
>>> import itertools as it
>>> it.cycle[int]
File "<stdin>", line 1, in <module>
TypeError: type 'itertools.cycle' is not subscriptable
>>> it.count[int]
TypeError: type 'itertools.repeat' is not subscriptable
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: type 'itertools.accumulate' is not subscriptable
>>> it.chain[int] # this is the only subscriptable class in itertools module
itertools.chain[int]
Has this already been discussed elsewhere?
No response given