MCPcopy
hub / github.com/python-trio/trio / get

Method get

src/trio/_core/_local.py:44–59  ·  view source on GitHub ↗

Gets the value of this :class:`RunVar` for the current run call.

(self, default: T | type[_NoValue] = _NoValue)

Source from the content-addressed store, hash-verified

42 _default: T | type[_NoValue] = attrs.field(default=_NoValue, alias="default")
43
44 def get(self, default: T | type[_NoValue] = _NoValue) -> T:
45 """Gets the value of this :class:`RunVar` for the current run call."""
46 try:
47 return cast("T", _run.GLOBAL_RUN_CONTEXT.runner._locals[self])
48 except AttributeError:
49 raise RuntimeError("Cannot be used outside of a run context") from None
50 except KeyError:
51 # contextvars consistency
52 # `type: ignore` awaiting https://github.com/python/mypy/issues/15553 to be fixed & released
53 if default is not _NoValue:
54 return default # type: ignore[return-value]
55
56 if self._default is not _NoValue:
57 return self._default # type: ignore[return-value]
58
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

Callers 15

setMethod · 0.95
_track_active_threadFunction · 0.45
active_thread_countFunction · 0.45
_send_message_to_trioFunction · 0.45
_open_processFunction · 0.45
_run_processFunction · 0.45
getaddrinfoFunction · 0.45
getnameinfoFunction · 0.45

Calls

no outgoing calls

Tested by 15

test_thread_cache_basicsFunction · 0.36
test_thread_cache_derefFunction · 0.36
test_idle_threads_exitFunction · 0.36
first_checkFunction · 0.36
second_checkFunction · 0.36
reset_checkFunction · 0.36
task1Function · 0.36
task2Function · 0.36
sync_checkFunction · 0.36
trivial_guest_runFunction · 0.36