mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
Merge pull request #1170 from Askaholic/impl-int-ratio-properties
Add int ratio properties
This commit is contained in:
@@ -52,6 +52,11 @@ with assertRaises(ZeroDivisionError):
|
||||
# real/imag attributes
|
||||
assert (1).real == 1
|
||||
assert (1).imag == 0
|
||||
# numerator/denominator attributes
|
||||
assert (1).numerator == 1
|
||||
assert (1).denominator == 1
|
||||
assert (10).numerator == 10
|
||||
assert (1).denominator == 1
|
||||
|
||||
assert_raises(OverflowError, lambda: 1 << 10 ** 100000)
|
||||
|
||||
|
||||
@@ -623,6 +623,16 @@ impl PyInt {
|
||||
fn imag(&self, _vm: &VirtualMachine) -> usize {
|
||||
0
|
||||
}
|
||||
|
||||
#[pyproperty]
|
||||
fn numerator(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyIntRef {
|
||||
zelf
|
||||
}
|
||||
|
||||
#[pyproperty]
|
||||
fn denominator(&self, _vm: &VirtualMachine) -> usize {
|
||||
1
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(FromArgs)]
|
||||
|
||||
Reference in New Issue
Block a user