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

Function get_special_method_error_msg

crates/vm/src/frame.rs:9658–9694  ·  view source on GitHub ↗

_Py_SpecialMethod _Py_SpecialMethods

(
    oparg: SpecialMethod,
    class_name: &str,
    can_suggest: bool,
)

Source from the content-addressed store, hash-verified

9656
9657/// _Py_SpecialMethod _Py_SpecialMethods
9658fn get_special_method_error_msg(
9659 oparg: SpecialMethod,
9660 class_name: &str,
9661 can_suggest: bool,
9662) -> String {
9663 if can_suggest {
9664 match oparg {
9665 SpecialMethod::Enter => format!(
9666 "'{class_name}' object does not support the context manager protocol (missed __enter__ method) but it supports the asynchronous context manager protocol. Did you mean to use 'async with'?"
9667 ),
9668 SpecialMethod::Exit => format!(
9669 "'{class_name}' object does not support the context manager protocol (missed __exit__ method) but it supports the asynchronous context manager protocol. Did you mean to use 'async with'?"
9670 ),
9671 SpecialMethod::AEnter => format!(
9672 "'{class_name}' object does not support the asynchronous context manager protocol (missed __aenter__ method) but it supports the context manager protocol. Did you mean to use 'with'?"
9673 ),
9674 SpecialMethod::AExit => format!(
9675 "'{class_name}' object does not support the asynchronous context manager protocol (missed __aexit__ method) but it supports the context manager protocol. Did you mean to use 'with'?"
9676 ),
9677 }
9678 } else {
9679 match oparg {
9680 SpecialMethod::Enter => format!(
9681 "'{class_name}' object does not support the context manager protocol (missed __enter__ method)"
9682 ),
9683 SpecialMethod::Exit => format!(
9684 "'{class_name}' object does not support the context manager protocol (missed __exit__ method)"
9685 ),
9686 SpecialMethod::AEnter => format!(
9687 "'{class_name}' object does not support the asynchronous context manager protocol (missed __aenter__ method)"
9688 ),
9689 SpecialMethod::AExit => format!(
9690 "'{class_name}' object does not support the asynchronous context manager protocol (missed __aexit__ method)"
9691 ),
9692 }
9693 }
9694}
9695
9696fn is_module_initializing(module: &PyObject, vm: &VirtualMachine) -> bool {
9697 let Ok(spec) = module.get_attr(&vm.ctx.new_str("__spec__"), vm) else {

Callers 1

execute_instructionMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected