Sets the value of this :class:`RunVar` for this current run call.
(self, value: T)
| 59 | raise LookupError(self) from None |
| 60 | |
| 61 | def set(self, value: T) -> RunVarToken[T]: |
| 62 | """Sets the value of this :class:`RunVar` for this current run |
| 63 | call. |
| 64 | |
| 65 | """ |
| 66 | try: |
| 67 | old_value = self.get() |
| 68 | except LookupError: |
| 69 | token = RunVarToken._empty(self) |
| 70 | else: |
| 71 | token = RunVarToken[T]._create(self, old_value) |
| 72 | |
| 73 | # This can't fail, because if we weren't in Trio context then the |
| 74 | # get() above would have failed. |
| 75 | _run.GLOBAL_RUN_CONTEXT.runner._locals[self] = value |
| 76 | return token |
| 77 | |
| 78 | def reset(self, token: RunVarToken[T]) -> None: |
| 79 | """Resets the value of this :class:`RunVar` to what it was |