We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 5f285a5 + 4ea960c commit 1575b9dCopy full SHA for 1575b9d
tests/snippets/builtin_complex.py
@@ -145,3 +145,7 @@
145
assert '(1-1j)' == str(1-1j)
146
assert '(1+1j)' == repr(1+1j)
147
assert '(1-1j)' == repr(1-1j)
148
+
149
+# __getnewargs__
150
+assert (3 + 5j).__getnewargs__() == (3.0, 5.0)
151
+assert (5j).__getnewargs__() == (0.0, 5.0)
vm/src/obj/objcomplex.rs
@@ -258,4 +258,12 @@ impl PyComplex {
258
let ret = Wrapping(re_hash) + Wrapping(im_hash) * Wrapping(pyhash::IMAG);
259
ret.0
260
}
261
262
+ #[pymethod(name = "__getnewargs__")]
263
+ fn complex_getnewargs(&self, vm: &VirtualMachine) -> PyResult {
264
+ let Complex64 { re, im } = self.value;
265
+ Ok(vm
266
+ .ctx
267
+ .new_tuple(vec![vm.ctx.new_float(re), vm.ctx.new_float(im)]))
268
+ }
269
0 commit comments