ASYNC113 & ASYNC121 false alarm with nested sync functions #287
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #286
I also did a search for
visit_FunctionDef
andvisit_AsyncFunctionDef
in the codebase and caught the same error for async113 (though it should very rarely occur for 113). At first glance a couple other visitors had the same problem, until I noticed those were cst visitors (which instead has anasynchronous
attribute).For 113 we could consider having the logic for
visit_FunctionDef
being the same asvisit_AsyncFunctionDef
instead of always settingself.aenter = False
in case users are transforming sync methods to async methods, but given such exotic stuff we're maybe better off staying away and avoiding super obscure false positives.We could consider adding a test that checks if any AST visitors only has one of the visitors defined, and could do the same for
With
/AsyncWith
andFor
/AsyncFor
(the latter which was in fact only caught in code review for #282). It will have a decent false-positive ratio though, but not very troublesome to have an ignore list or declare dummy methods.Another approach is preferring cst over AST, and I've been inconsistent when creating new visitors despite #124. I should try and compile pros/cons and write a comment over there.