I am trying to specify the type of an itertool.count object in Python, like so:
from itertools import count
c: count = count()
However, running mypy yields the following error:
test.py:3: error: Function "itertools.count" is not valid as a type
test.py:3: note: Perhaps you need "Callable[...]" or a callback protocol?
Found 1 error in 1 file (checked 1 source file)
It seems to be caused by the fact that itertools.count behaves like a function. However, it returns an itertools.count object, as shown by
In [1]: import itertools
In [2]: type(itertools.count()) is itertools.count
Out[2]: True
Then, how should I specify the type of the result of count() ?