Add await to empty context hack#19777
Conversation
|
(and confirmed that I'm surprised that this was the only problem caused by stub definitions. I'll open a follow-up PR to sync variance in other |
This comment has been minimized.
This comment has been minimized.
ilevkivskyi
left a comment
There was a problem hiding this comment.
Thanks for the catch! I have one suggestion.
| if isinstance(s.expr, (CallExpr, ListExpr, TupleExpr, DictExpr, SetExpr, OpExpr)): | ||
| if isinstance( | ||
| s.expr, (CallExpr, ListExpr, TupleExpr, DictExpr, SetExpr, OpExpr, AwaitExpr) | ||
| ): |
There was a problem hiding this comment.
What about using isinstance(s.expr, AwaitExpr) and isinstance(s.expr.expr, CallExpr)? This will save us some pointless busy-work for cases like return await some_name.
There was a problem hiding this comment.
Hm, yes, makes sense. I doubt that await not_a_call accounts for some significant portion of await expressions, but this shouldn't harm.
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Fixes #19716. It is a follow-up to #19767 and was missed there due to malformed test stubs (the same testcase fails when run by full mypy against typeshed, I did not notice missing AwaitExpr because of the passing test...). I synced typevar variance with typeshed definitions and added AwaitExpr to the list of context-dependent exprs. Cc @ilevkivskyi