called within a method that changes states. method must also use the ``@declare_states()`` decorator.
(self, expected: _StateChangeState)
| 172 | |
| 173 | @contextlib.contextmanager |
| 174 | def _expect_state(self, expected: _StateChangeState) -> Iterator[Any]: |
| 175 | """called within a method that changes states. |
| 176 | |
| 177 | method must also use the ``@declare_states()`` decorator. |
| 178 | |
| 179 | """ |
| 180 | assert self._next_state is _StateChangeStates.CHANGE_IN_PROGRESS, ( |
| 181 | "Unexpected call to _expect_state outside of " |
| 182 | "state-changing method" |
| 183 | ) |
| 184 | |
| 185 | self._next_state = expected |
| 186 | try: |
| 187 | yield |
| 188 | except: |
| 189 | raise |
| 190 | else: |
| 191 | if self._state is not expected: |
| 192 | raise sa_exc.IllegalStateChangeError( |
| 193 | f"Unexpected state change to {self._state!r}", code="isce" |
| 194 | ) |
| 195 | finally: |
| 196 | self._next_state = _StateChangeStates.CHANGE_IN_PROGRESS |
no outgoing calls