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: 2 additions & 0 deletions tests/snippets/tuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@

b = (1,2,3)
assert b.index(2) == 1

assert b.__doc__ == "tuple() -> empty tuple\ntuple(iterable) -> tuple initialized from iterable's items\n\nIf the argument is a tuple, the return value is the same object."
9 changes: 9 additions & 0 deletions vm/src/obj/objtuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ pub fn tuple_contains(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {

pub fn init(context: &PyContext) {
let tuple_type = &context.tuple_type;
let tuple_doc = "tuple() -> empty tuple
tuple(iterable) -> tuple initialized from iterable's items

If the argument is a tuple, the return value is the same object.";
context.set_attr(&tuple_type, "__add__", context.new_rustfunc(tuple_add));
context.set_attr(&tuple_type, "__eq__", context.new_rustfunc(tuple_eq));
context.set_attr(
Expand All @@ -313,5 +317,10 @@ pub fn init(context: &PyContext) {
context.set_attr(&tuple_type, "__le__", context.new_rustfunc(tuple_le));
context.set_attr(&tuple_type, "__gt__", context.new_rustfunc(tuple_gt));
context.set_attr(&tuple_type, "__ge__", context.new_rustfunc(tuple_ge));
context.set_attr(
&tuple_type,
"__doc__",
context.new_str(tuple_doc.to_string()),
);
context.set_attr(&tuple_type, "index", context.new_rustfunc(tuple_index));
}