Skip to content

Commit 5f807e2

Browse files
author
Stefan Behnel
committed
minor fixes and cythonisations
1 parent 08c2867 commit 5f807e2

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/quicktions.pyx

+10-8
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ cdef class Fraction:
188188

189189
elif isinstance(numerator, Decimal):
190190
value = Fraction.from_decimal(numerator)
191-
self._numerator = value._numerator
192-
self._denominator = value._denominator
191+
self._numerator = (<Fraction>value)._numerator
192+
self._denominator = (<Fraction>value)._denominator
193193
return
194194

195195
else:
@@ -429,6 +429,8 @@ cdef class Fraction:
429429

430430
def __pos__(a):
431431
"""+a: Coerces a subclass instance to Fraction"""
432+
if type(a) is Fraction:
433+
return a
432434
return Fraction(a._numerator, a._denominator, _normalize=False)
433435

434436
def __neg__(a):
@@ -494,15 +496,15 @@ cdef class Fraction:
494496
"""complex(self) == complex(float(self), 0)"""
495497
return complex(float(self))
496498

497-
@property
498-
def real(self):
499+
property real:
499500
"""Real numbers are their real component."""
500-
return +self
501+
def __get__(self):
502+
return +self
501503

502-
@property
503-
def imag(self):
504+
property imag:
504505
"""Real numbers have no imaginary component."""
505-
return 0
506+
def __get__(self):
507+
return 0
506508

507509
def conjugate(self):
508510
"""Conjugate is a no-op for Reals."""

0 commit comments

Comments
 (0)