mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-39350: Fix fractions for int subclasses (GH-18375)
Fix regression in fractions.Fraction if the numerator and/or the denominator is an int subclass. The math.gcd() function is now used to normalize the numerator and denominator. math.gcd() always return a int type. Previously, the GCD type depended on numerator and denominator.
This commit is contained in:
parent
60ac6ed557
commit
dc7a50d73a
4 changed files with 34 additions and 7 deletions
|
@ -155,13 +155,9 @@ class Fraction(numbers.Rational):
|
|||
if denominator == 0:
|
||||
raise ZeroDivisionError('Fraction(%s, 0)' % numerator)
|
||||
if _normalize:
|
||||
if type(numerator) is int is type(denominator):
|
||||
# *very* normal case
|
||||
g = math.gcd(numerator, denominator)
|
||||
if denominator < 0:
|
||||
g = -g
|
||||
else:
|
||||
g = _gcd(numerator, denominator)
|
||||
g = math.gcd(numerator, denominator)
|
||||
if denominator < 0:
|
||||
g = -g
|
||||
numerator //= g
|
||||
denominator //= g
|
||||
self._numerator = numerator
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue