Skip to content

Commit e9d37bf

Browse files
committed
Fix set_name error message when arguments are invalid
1 parent b0d5155 commit e9d37bf

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

Lib/test/test_property.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,6 @@ def __doc__(cls):
216216
return 'Second'
217217
self.assertEqual(A.__doc__, 'Second')
218218

219-
# TODO: RUSTPYTHON
220-
@unittest.expectedFailure
221219
def test_property_set_name_incorrect_args(self):
222220
p = property()
223221

vm/src/builtins/property.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
use super::{PyType, PyTypeRef};
55
use crate::common::lock::PyRwLock;
6+
use crate::function::PosArgs;
67
use crate::{
78
class::PyClassImpl,
89
function::{FuncArgs, PySetterValue},
@@ -154,6 +155,23 @@ impl PyProperty {
154155
*self.doc.write() = value;
155156
}
156157

158+
#[pymethod(magic)]
159+
fn set_name(&self, args: PosArgs, vm: &VirtualMachine) -> PyResult<()> {
160+
let arg_len = args.into_vec().len();
161+
162+
if arg_len != 2 {
163+
Err(vm.new_exception_msg(
164+
vm.ctx.exceptions.type_error.to_owned(),
165+
format!(
166+
"__set_name__() takes 2 positional arguments but {} were given",
167+
arg_len
168+
),
169+
))
170+
} else {
171+
Ok(())
172+
}
173+
}
174+
157175
// Python builder functions
158176

159177
#[pymethod]

0 commit comments

Comments
 (0)