Currently WrongListComprehensionVisitor is not tested with async for comprehensions.
It might work, it might not work.
What needs to be done?
async for cases here: https://github.com/wemake-services/wemake-python-styleguide/blob/master/tests/test_visitors/test_ast/test_general/test_wrong_keyword/test_comprehensions.py'nodes = [node {0}for node in 'abc']' and then format this string with either 'async ' or ''It is not that simple.
Ast can't parse single async comprehension without async function wrapped around.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "python3.6/ast.py", line 35, in parse
return compile(source, filename, mode, PyCF_ONLY_AST)
File "<unknown>", line 2
nodes = [node async for node in 'abc' if node != 'a' if node != 'b' if node != 'c']
^
SyntaxError: invalid syntax
@sobolevn how about wrap all comprehensions with something like
async_wrapper = """
async def d():
{comprehension}
"""
list_ifs_multiple = """
nodes = [node {async}for node in 'abc' if node != 'a' if node != 'b' if node != 'c']
"""
@AlwxSin hm, I have totally missed it!
Yes, your solution seems reasonable. Let's do that. Are you willing to put this together in a PR?
Is it worth to create a fixture called async_wrapper that can be reused latter for other tests?
Yeah, I'll do it.
Most helpful comment
Yeah, I'll do it.