(real: Callable[[_T], None], *, before: bool)
| 102 | |
| 103 | |
| 104 | def interrupt_once(real: Callable[[_T], None], *, before: bool) -> Callable[[_T], None]: |
| 105 | pending = True |
| 106 | |
| 107 | def call(instance: _T) -> None: |
| 108 | nonlocal pending |
| 109 | if pending and before: |
| 110 | pending = False |
| 111 | raise Interrupt |
| 112 | real(instance) |
| 113 | if pending: |
| 114 | pending = False |
| 115 | raise Interrupt |
| 116 | |
| 117 | return call |
| 118 | |
| 119 | |
| 120 | class Interrupt(BaseException): |
no outgoing calls