_Py_SpecialMethod _Py_SpecialMethods
(
oparg: SpecialMethod,
class_name: &str,
can_suggest: bool,
)
| 9656 | |
| 9657 | /// _Py_SpecialMethod _Py_SpecialMethods |
| 9658 | fn 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 | |
| 9696 | fn is_module_initializing(module: &PyObject, vm: &VirtualMachine) -> bool { |
| 9697 | let Ok(spec) = module.get_attr(&vm.ctx.new_str("__spec__"), vm) else { |