|
1 | 1 | # type: ignore |
2 | 2 | # ARG --enable=ASYNC102,ASYNC120 |
3 | | -# NOASYNCIO # TODO: support asyncio shields |
| 3 | +# ASYNCIO_NO_ERROR # ASYNC102 not applicable to asyncio |
4 | 4 | from contextlib import asynccontextmanager |
5 | 5 |
|
6 | 6 | import trio |
@@ -310,3 +310,38 @@ async def foo_nested_cs(): |
310 | 310 | # treat __aexit__ as a critical scope |
311 | 311 | async def __aexit__(): |
312 | 312 | await foo() # error: 4, Statement("__aexit__", lineno-1) |
| 313 | + |
| 314 | + |
| 315 | +# exclude `finally: await x.aclose()` with no arguments |
| 316 | +async def foo_aclose_noargs(): |
| 317 | + # no type tracking in this check, we allow any call that looks like |
| 318 | + # `await [...].aclose()` |
| 319 | + x = None |
| 320 | + |
| 321 | + try: |
| 322 | + ... |
| 323 | + except BaseException: |
| 324 | + await x.aclose() |
| 325 | + await x.y.aclose() |
| 326 | + finally: |
| 327 | + await x.aclose() |
| 328 | + await x.y.aclose() |
| 329 | + |
| 330 | + |
| 331 | +# should still raise errors if there's args, as that indicates it's a non-standard aclose |
| 332 | +async def foo(): |
| 333 | + # no type tracking in this check |
| 334 | + x = None |
| 335 | + |
| 336 | + try: |
| 337 | + ... |
| 338 | + except BaseException: |
| 339 | + await x.aclose(foo) # ASYNC102: 8, Statement("BaseException", lineno-1) |
| 340 | + await x.aclose(bar=foo) # ASYNC102: 8, Statement("BaseException", lineno-2) |
| 341 | + await x.aclose(*foo) # ASYNC102: 8, Statement("BaseException", lineno-3) |
| 342 | + await x.aclose(None) # ASYNC102: 8, Statement("BaseException", lineno-4) |
| 343 | + finally: |
| 344 | + await x.aclose(foo) # ASYNC102: 8, Statement("try/finally", lineno-8) |
| 345 | + await x.aclose(bar=foo) # ASYNC102: 8, Statement("try/finally", lineno-9) |
| 346 | + await x.aclose(*foo) # ASYNC102: 8, Statement("try/finally", lineno-10) |
| 347 | + await x.aclose(None) # ASYNC102: 8, Statement("try/finally", lineno-11) |
0 commit comments