Skip to content

Commit 48254ac

Browse files
authored
Merge pull request RustPython#4165 from jopemachine/fix-test-prop
Fix `property.__set_name__` error message when arguments are invalid
2 parents 4a579b5 + e325a00 commit 48254ac

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},
@@ -122,6 +123,23 @@ impl PyProperty {
122123
*self.doc.write() = value;
123124
}
124125

126+
#[pymethod(magic)]
127+
fn set_name(&self, args: PosArgs, vm: &VirtualMachine) -> PyResult<()> {
128+
let arg_len = args.into_vec().len();
129+
130+
if arg_len != 2 {
131+
Err(vm.new_exception_msg(
132+
vm.ctx.exceptions.type_error.to_owned(),
133+
format!(
134+
"__set_name__() takes 2 positional arguments but {} were given",
135+
arg_len
136+
),
137+
))
138+
} else {
139+
Ok(())
140+
}
141+
}
142+
125143
// Python builder functions
126144

127145
#[pymethod]

0 commit comments

Comments
 (0)