| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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.
Sorry, something went wrong.
|
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 defn.type in-place is a sketchy thing (and also all the code around awaitable generators is sketchy, but I knew about this when I started the whole two-phase checking thing). After some thinking, we probably shouldn't do the wrapping at all for dynamic functions for consistency with regular async def: 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) |
Sorry, something went wrong.
|
Let's try wrapping both! |
Sorry, something went wrong.
OK, let's see how it works. Btw there is another quirk that needed fixing, the Use "-> None" if function does not return a value 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) |
Sorry, something went wrong.
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Sorry, something went wrong.
It didn't really work, whatever direction I go, a whole can of worms opens. So let's just fix the regression. The PR as it is now should be strictly better than both 2.0 (no crash) and 1.20 (dynamic functions don't stop being such when deferred). |
Sorry, something went wrong.
|
I can confirm this fixes the issue in our code base. Thanks for picking this up! |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Fixes #21426
Fix is straightforward: make the new logic more 1:1 with the old one (which was not the case for untyped functions).