You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Prime number sieve with generatorsMypy with static typing example does not pass on mypy. It's also not clear what needs to be done to make the example work. Typing numbers seems to work.
To Reproduce
# Taken directly from https://mypy-lang.org/examples.htmlimportitertoolsfromtypingimportIteratordefiter_primes() ->Iterator[int]:
# An iterator of all numbers between 2 and# +infinitynumbers=itertools.count(2)
# Generate primes foreverwhileTrue:
# Get the first number from the iterator# (always a prime)prime=next(numbers)
yieldprime# This code iteratively builds up a chain# of filters...numbers=filter(prime.__rmod__, numbers)
forpiniter_primes():
ifp>1000:
breakprint(p)
main.py:18: error: Incompatible types in assignment (expression has type "filter[int]", variable has type "count[int]") [assignment]
Found 1 error in 1 file (checked 1 source file)
Your Environment
Mypy version used: mypy master, mypy 1.10.0 (I tried all the versions on the playground on https://mypy-play.net/, but none seem to work. I think it worked with 0.750 but I haven't tested it to be sure.)
Mypy command-line flags: None
Mypy configuration options from mypy.ini (and other config files): None
Python version used: 3.12, 3.9
Suggested fix
I guess changing numbers = itertools.count(2) to numbers: Iterator[int] = itertools.count(2) seems to work. Perhaps we should update the mypy example?
The text was updated successfully, but these errors were encountered:
Bug Report
The
Prime number sieve with generators
Mypy with static typing
example does not pass on mypy.It's also not clear what needs to be done to make the example work.Typingnumbers
seems to work.To Reproduce
https://mypy-play.net/?mypy=master&python=3.9&gist=52970ddb2c5cd827dafa8f8af5219f89
Expected Behavior
No errors.
Actual Behavior
Your Environment
mypy.ini
(and other config files): NoneSuggested fix
I guess changing
numbers = itertools.count(2)
tonumbers: Iterator[int] = itertools.count(2)
seems to work. Perhaps we should update the mypy example?The text was updated successfully, but these errors were encountered: