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

Method throw

crates/vm/src/builtins/asyncgenerator.rs:341–380  ·  view source on GitHub ↗
(
        &self,
        exc_type: PyObjectRef,
        exc_val: OptionalArg,
        exc_tb: OptionalArg,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

339
340 #[pymethod]
341 fn throw(
342 &self,
343 exc_type: PyObjectRef,
344 exc_val: OptionalArg,
345 exc_tb: OptionalArg,
346 vm: &VirtualMachine,
347 ) -> PyResult {
348 match self.state.load() {
349 AwaitableState::Closed => {
350 return Err(
351 vm.new_runtime_error("cannot reuse already awaited __anext__()/asend()")
352 );
353 }
354 AwaitableState::Init => {
355 if self.ag.running_async.load() {
356 self.state.store(AwaitableState::Closed);
357 return Err(
358 vm.new_runtime_error("anext(): asynchronous generator is already running")
359 );
360 }
361 self.ag.running_async.store(true);
362 self.state.store(AwaitableState::Iter);
363 }
364 AwaitableState::Iter => {}
365 }
366
367 warn_deprecated_throw_signature(&exc_val, &exc_tb, vm)?;
368 let res = self.ag.inner.throw(
369 self.ag.as_object(),
370 exc_type,
371 exc_val.unwrap_or_none(vm),
372 exc_tb.unwrap_or_none(vm),
373 vm,
374 );
375 let res = PyAsyncGenWrappedValue::unbox(&self.ag, res, vm);
376 if res.is_err() {
377 self.set_closed();
378 }
379 res
380 }
381
382 #[pymethod]
383 fn close(&self, vm: &VirtualMachine) -> PyResult<()> {

Callers 2

closeMethod · 0.45
sendMethod · 0.45

Calls 15

is_errMethod · 0.80
set_closedMethod · 0.80
new_stop_iterationMethod · 0.80
ignored_closeMethod · 0.80
yield_closeMethod · 0.80
into_async_pyresultMethod · 0.80
handle_resultMethod · 0.80
ErrClass · 0.50
loadMethod · 0.45
storeMethod · 0.45
as_objectMethod · 0.45

Tested by

no test coverage detected