MCPcopy Create free account
hub / github.com/RustPython/RustPython / unbound_cell_exception

Method unbound_cell_exception

crates/vm/src/frame.rs:1935–1961  ·  view source on GitHub ↗
(
        &self,
        localsplus_idx: usize,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

1933 }
1934
1935 fn unbound_cell_exception(
1936 &self,
1937 localsplus_idx: usize,
1938 vm: &VirtualMachine,
1939 ) -> PyBaseExceptionRef {
1940 use rustpython_compiler_core::bytecode::CO_FAST_FREE;
1941 let kind = self
1942 .code
1943 .localspluskinds
1944 .get(localsplus_idx)
1945 .copied()
1946 .unwrap_or(0);
1947 if kind & CO_FAST_FREE != 0 {
1948 let name = self.localsplus_name(localsplus_idx);
1949 vm.new_name_error(
1950 format!("cannot access free variable '{name}' where it is not associated with a value in enclosing scope"),
1951 name.to_owned(),
1952 )
1953 } else {
1954 // Both merged cells (LOCAL|CELL) and non-merged cells get unbound local error
1955 let name = self.localsplus_name(localsplus_idx);
1956 vm.new_exception_msg(
1957 vm.ctx.exceptions.unbound_local_error.to_owned(),
1958 format!("local variable '{name}' referenced before assignment").into(),
1959 )
1960 }
1961 }
1962
1963 /// Get the variable name for a localsplus index.
1964 fn localsplus_name(&self, idx: usize) -> &'static PyStrInterned {

Callers 1

execute_instructionMethod · 0.80

Calls 5

localsplus_nameMethod · 0.80
new_name_errorMethod · 0.80
new_exception_msgMethod · 0.80
getMethod · 0.45
to_ownedMethod · 0.45

Tested by

no test coverage detected