forked from Rust-related/RustPython
Fix set_name error message when arguments are invalid
This commit is contained in:
2
Lib/test/test_property.py
vendored
2
Lib/test/test_property.py
vendored
@@ -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()
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user