|
25 | 25 | flatten_preserving_comments, |
26 | 26 | fnmatch_qualified_name_cst, |
27 | 27 | func_has_decorator, |
28 | | - identifier_to_string, |
29 | 28 | iter_guaranteed_once_cst, |
30 | 29 | with_has_call, |
31 | 30 | ) |
@@ -492,33 +491,12 @@ def _is_exception_suppressing_context_manager(self, node: cst.With) -> bool: |
492 | 491 | is not None |
493 | 492 | ) |
494 | 493 |
|
495 | | - def _checkpoint_with(self, node: cst.With): |
496 | | - """Conditionally checkpoints entry/exit of With. |
497 | | -
|
498 | | - If the with only contains calls to open_nursery/create_task_group, it's a schedule |
499 | | - point but not a cancellation point, so we treat it as a checkpoint for async91x |
500 | | - but not for async100. |
501 | | - """ |
502 | | - if getattr(node, "asynchronous", None): |
503 | | - for item in node.items: |
504 | | - if not ( |
505 | | - isinstance(item.item, cst.Call) |
506 | | - and identifier_to_string(item.item.func) |
507 | | - in ( |
508 | | - "trio.open_nursery", |
509 | | - "anyio.create_task_group", |
510 | | - ) |
511 | | - ): |
512 | | - self.checkpoint() |
513 | | - break |
514 | | - else: |
515 | | - self.uncheckpointed_statements = set() |
516 | | - |
517 | 494 | # Async context managers can reasonably checkpoint on either or both of entry and |
518 | 495 | # exit. Given that we can't tell which, we assume "both" to avoid raising a |
519 | 496 | # missing-checkpoint warning when there might in fact be one (i.e. a false alarm). |
520 | 497 | def visit_With_body(self, node: cst.With): |
521 | | - self._checkpoint_with(node) |
| 498 | + if getattr(node, "asynchronous", None): |
| 499 | + self.checkpoint() |
522 | 500 |
|
523 | 501 | # if this might suppress exceptions, we cannot treat anything inside it as |
524 | 502 | # checkpointing. |
@@ -577,7 +555,8 @@ def leave_With(self, original_node: cst.With, updated_node: cst.With): |
577 | 555 | self.restore_state(original_node) |
578 | 556 | self.uncheckpointed_statements.update(prev_checkpoints) |
579 | 557 |
|
580 | | - self._checkpoint_with(original_node) |
| 558 | + if getattr(original_node, "asynchronous", None): |
| 559 | + self.checkpoint() |
581 | 560 | return updated_node |
582 | 561 |
|
583 | 562 | # error if no checkpoint since earlier yield or function entry |
|
0 commit comments