8000 fix assertionerror with infinite loop in context manager (#296) · python-trio/flake8-async@a42ad99 · GitHub
[go: up one dir, main page]

Skip to content

Commit a42ad99

Browse files
authored
fix assertionerror with infinite loop in context manager (#296)
1 parent db5317c commit a42ad99

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

docs/changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Changelog
44

55
`CalVer, YY.month.patch <https://calver.org/>`_
66

7+
24.9.5
8+
======
9+
- Fix crash when analyzing code with infinite loop inside context manager.
10+
711
24.9.4
812
======
913
- Add :ref:`ASYNC122 <async122>` delayed-entry-of-relative-cancelscope.

flake8_async/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939

4040
# CalVer: YY.month.patch, e.g. first release of July 2022 == "22.7.1"
41-
__version__ = "24.9.4"
41+
__version__ = "24.9.5"
4242

4343

4444
# taken from https://github.com/Zac-HD/shed

flake8_async/visitors/visitor91x.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ def error_91x(
452452
node: cst.Return | cst.FunctionDef | cst.Yield,
453453
statement: Statement,
454454
) -> bool:
455-
assert not isinstance(statement, ArtificialStatement)
455+
assert not isinstance(statement, ArtificialStatement), statement
456456

457457
if isinstance(node, cst.FunctionDef):
458458
msg = "exit"
@@ -768,7 +768,7 @@ def leave_While_body(self, node: cst.For | cst.While):
768768
| self.uncheckpointed_statements
769769
| self.loop_state.uncheckpointed_before_continue
770770
):
771-
if stmt == ARTIFICIAL_STATEMENT:
771+
if isinstance(stmt, ArtificialStatement):
772772
continue
773773
any_error |= self.error_91x(err_node, stmt)
774774

tests/autofix_files/async100.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,12 @@ async def more_nested_tests():
121121
async def foo():
122122
with trio.fail_after(1):
123123
yield
124+
125+
126+
# This previously caused an AssertionError, see issue #295
127+
async def fn(timeout):
128+
with trio.fail_after(timeout):
129+
while True:
130+
if condition():
131+
return
132+
await trio.sleep(1)

tests/eval_files/async100.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,12 @@ async def more_nested_tests():
121121
async def foo():
122122
with trio.fail_after(1):
123123
yield
124+
125+
126+
# This previously caused an AssertionError, see issue #295
127+
async def fn(timeout):
128+
with trio.fail_after(timeout):
129+
while True:
130+
if condition():
131+
return
132+
await trio.sleep(1)

0 commit comments

Comments
 (0)
0