Skip to content

Commit 33523d4

Browse files
committed
Change int.conjugate() to return a new int
This results in the correct behavior (that is, matching CPython) for both int and bool types. Also adding a bool conjugate test.
1 parent a95747f commit 33523d4

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

tests/snippets/bools.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,5 @@ def __bool__(self):
4646
assert False * 7 == 0
4747
assert True > 0
4848
assert int(True) == 1
49-
#assert True.conjugate() == 1
49+
assert True.conjugate() == 1
50+
assert isinstance(True.conjugate(), int)

vm/src/obj/objint.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,8 @@ fn int_bit_length(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
491491

492492
fn int_conjugate(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
493493
arg_check!(vm, args, required = [(i, Some(vm.ctx.int_type()))]);
494-
Ok(i.clone())
494+
let v = get_value(i);
495+
Ok(vm.ctx.new_int(v))
495496
}
496497

497498
pub fn init(context: &PyContext) {

0 commit comments

Comments
 (0)