MCPcopy Index your code
hub / github.com/RustPython/RustPython / enter

Method enter

crates/stdlib/src/contextvars.rs:90–106  ·  view source on GitHub ↗
(zelf: &Py<Self>, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

88 }
89
90 fn enter(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<()> {
91 if zelf.inner.entered.get() {
92 let msg = format!(
93 "cannot enter context: {} is already entered",
94 zelf.as_object().repr(vm)?
95 );
96 return Err(vm.new_runtime_error(msg));
97 }
98
99 super::CONTEXTS.with_borrow_mut(|ctxs| {
100 zelf.inner.idx.set(ctxs.len());
101 ctxs.push(zelf.to_owned());
102 });
103 zelf.inner.entered.set(true);
104
105 Ok(())
106 }
107
108 fn exit(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<()> {
109 if !zelf.inner.entered.get() {

Callers

nothing calls this directly

Calls 6

ErrClass · 0.50
getMethod · 0.45
setMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45
to_ownedMethod · 0.45

Tested by

no test coverage detected