Skip to content

Commit 37fe202

Browse files
authored
Merge pull request RustPython#1756 from minhnhdo/master
Add __pos__ to PyComplex
2 parents 176fa58 + 914454e commit 37fe202

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

tests/snippets/builtin_complex.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@
5757
assert complex(1) ** 2 == 1
5858
assert 2 ** complex(2) == 4
5959

60+
# __pos__
61+
62+
assert +complex(0, 1) == complex(0, 1)
63+
assert +complex(1, 0) == complex(1, 0)
64+
assert +complex(1, -1) == complex(1, -1)
65+
assert +complex(0, 0) == complex(0, 0)
66+
6067
# __neg__
6168

6269
assert -complex(1, -1) == complex(-1, 1)

vm/src/obj/objcomplex.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ impl PyComplex {
183183
self.divmod(other, vm)
184184
}
185185

186+
#[pymethod(name = "__pos__")]
187+
fn pos(&self) -> Complex64 {
188+
self.value
189+
}
190+
186191
#[pymethod(name = "__neg__")]
187192
fn neg(&self) -> Complex64 {
188193
-self.value

0 commit comments

Comments
 (0)