Fix broken refactor of awaitable generator patching#21435
Fix broken refactor of awaitable generator patching#21435ilevkivskyi wants to merge 2 commits intopython:masterfrom
Conversation
This comment has been minimized.
This comment has been minimized.
JukkaL
left a comment
There was a problem hiding this comment.
It seems to regress unannotated functions -- their bodies may now be checked (but this wasn't the case in 1.20):
import types
@types.coroutine
def f(x):
1 + "x" # Error (but shouldn't be, since no annotation)
yield
If I omit @types.coroutine, there is no error reported.
|
Hm, this is kind of a pre-existing problem, I can reproduce this on older versions with e.g. a deferral (or otherwise force re-visiting the function). But now the issue is more prominent, because with two-phase checking every function is in some sense deferred. Patching the After some thinking, we probably shouldn't do the wrapping at all for dynamic functions for consistency with regular async def f(): ...
reveal_type(f) # "def () -> Any", not "def () -> Coroutine[Any, Any, Any]"Or vice-versa, we should wrap both. So what would it be? @JukkaL (to be clear both ways have relatively simple fixes) |
|
Let's try wrapping both! |
OK, let's see how it works. Btw there is another quirk that needed fixing, the note is added based on some random heuristics. I made some changes to preserve the current behavior (just to minimize number of ~unrelated changes in this PR) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
6fb2f40 to
6a6aa49
Compare
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Fixes #21426
Fix is straightforward: make the new logic more 1:1 with the old one (which was not the case for untyped functions).