Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Lib/test/test_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,6 @@ def __doc__(cls):
return 'Second'
self.assertEqual(A.__doc__, 'Second')

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_property_set_name_incorrect_args(self):
p = property()

Expand Down
18 changes: 18 additions & 0 deletions vm/src/builtins/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
use super::{PyType, PyTypeRef};
use crate::common::lock::PyRwLock;
use crate::function::PosArgs;
use crate::{
class::PyClassImpl,
function::{FuncArgs, PySetterValue},
Expand Down Expand Up @@ -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
),
Comment on lines +133 to +136

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message is common python type error which we are not handling well. We'd better to find enhance the general argument error handling instead of this way.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry, the given type is PosArgs. So no way to do it in shared code.

))
} else {
Ok(())
}
}

// Python builder functions

#[pymethod]
Expand Down