Open nmzgnv opened 8 months ago
I agree this is reasonable.
Is it possible to rewrite this with a single await asyncio.gather
?
I have no idea about asyncio.gather
, but if error occures on the first iteration, you can use await anext(...)
:
async def async_gen():
for i in range(10):
raise ValueError('Hello')
yield i
async def main():
await anext(async_gen())
if an error occurs after many iterations, then you need to go through the iterator completely before the error occurs. Another tric:
async def main():
_ = [elem async for elem in async_gen()]
@RonnyPfannschmidt - Do you have an opinion on this one, before I consider changing the rule?
I'm a bit torn on this one
The most beautiful Syntax is the false positive
The listcomp makes the intent more clear
This is one of the cases where I wish thered be a consume helper
What's wrong
I want to test that async iterator raises error.
Receive unexpected error
PT012 'pytest.raises()' block should contain a single simple statement
, but the statement is already simple.How it should work
not raise PT012 for simple async for loops as with empty context managers https://github.com/m-burst/flake8-pytest-style/blob/master/docs/rules/PT012.md
System information