Skip to content

Commit

Permalink
Restore back _normalize kwarg for the Fraction.__new__()
Browse files Browse the repository at this point in the history
  • Loading branch information
skirpichev committed Feb 11, 2023
1 parent 9e66b5a commit 4324391
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions Lib/fractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class Fraction(numbers.Rational):
__slots__ = ('_numerator', '_denominator')

# We're immutable, so use __new__ not __init__
def __new__(cls, numerator=0, denominator=None):
def __new__(cls, numerator=0, denominator=None, *, _normalize=True):
"""Constructs a Rational.
Takes a string like '3/2' or '1.5', another Rational instance, a
Expand Down Expand Up @@ -279,11 +279,12 @@ def __new__(cls, numerator=0, denominator=None):

if denominator == 0:
raise ZeroDivisionError('Fraction(%s, 0)' % numerator)
g = math.gcd(numerator, denominator)
if denominator < 0:
g = -g
numerator //= g
denominator //= g
if _normalize:
g = math.gcd(numerator, denominator)
if denominator < 0:
g = -g
numerator //= g
denominator //= g
self._numerator = numerator
self._denominator = denominator
return self
Expand Down

0 comments on commit 4324391

Please sign in to comment.