Fix set_name error message when arguments are invalid

This commit is contained in:
Gyubong
2022-09-16 17:12:54 +09:00
committed by Jeong YunWon
parent e5735cde67
commit d4aa062441
2 changed files with 18 additions and 2 deletions

View File

@@ -216,8 +216,6 @@ class PropertyTests(unittest.TestCase):
return 'Second'
self.assertEqual(A.__doc__, 'Second')
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_property_set_name_incorrect_args(self):
p = property()

View File

@@ -3,6 +3,7 @@
*/
use super::{PyType, PyTypeRef};
use crate::common::lock::PyRwLock;
use crate::function::PosArgs;
use crate::{
class::PyClassImpl,
function::{FuncArgs, PySetterValue},
@@ -122,6 +123,23 @@ impl PyProperty {
*self.doc.write() = value;
}
#[pymethod(magic)]
fn set_name(&self, args: PosArgs, vm: &VirtualMachine) -> PyResult<()> {
let arg_len = args.into_vec().len();
if arg_len != 2 {
Err(vm.new_exception_msg(
vm.ctx.exceptions.type_error.to_owned(),
format!(
"__set_name__() takes 2 positional arguments but {} were given",
arg_len
),
))
} else {
Ok(())
}
}
// Python builder functions
#[pymethod]