-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Failure to account for None-returning generators in StopIteration.args #18073
Comments
If a generator returns None, the StopIteration.args tuple is empty. The fact we explicitly checks for it and in that case we return none looks now an error for Mypy. I don't see an obvious way around it. Maybe related to python/mypy#1933 which is an historical issue (opened in 2016). Reported in python/mypy#18073
This seems related to #17427, and the error looks correct to me. The function is declared as returning |
What Jelle said. Note that there’s no connection in the type system between Also, you may find it easier to use |
…ting Work around the issue reported in python/mypy#18073 Thank you very much, @brianschubert, for pointing it out!
Yes, the primer in #17427 indeed shows the changes in psycopg check. Observation: If expr is Any, isn't "expr if cond else None" an Any too? However, thank you very much for pointing out the use of |
No, it is |
If a generator returns None, the StopIteration.args tuple is empty. The fact we explicitly checks for it and in that case we return none looks now an error for Mypy. I don't see an obvious way around it. Maybe related to python/mypy#1933 which is an historical issue (opened in 2016). Reported in python/mypy#18073
In psycopg 3 we have generators returning a final result, which sometimes is None, sometimes a different object. We also have some consumers of these generators, which wait for I/O completion according to the values yielded by the generators and finally return the final generator result.
Something similar can be represented with the following code:
If a generator returns
None
, theStopIteration.args
tuple will empty, which is accounted for in thewait()
's return statement (removing the check will cause an IndexError onwait(none_gen())
). However, since Mypy 1.12, the return statement in the wait returns an error:This wasn't reported as error in Mypy 1.11
The text was updated successfully, but these errors were encountered: