Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-39350: Fix regression introduced when fractions.gcd was removed #18309

Open
wants to merge 3 commits into
base: master
from

Conversation

@mdickinson
Copy link
Member

mdickinson commented Feb 2, 2020

This PR is a quick fix for the breakage introduced in #18021, which removed the _gcd function while the core code was still using it.

Possibly the behaviour of Fraction for non-integers should be different, but I think it makes sense to fix the breakage immediately and then discuss whether we want to make behavioural changes.

No news entry needed, because the broken code hasn't make it into any release or prerelease.

https://bugs.python.org/issue39350

@hroncok

This comment has been minimized.

Copy link
Contributor

hroncok commented Feb 2, 2020

No news entry needed, because the broken code hasn't make it into any release or prerelease.

The broken code made it to 3.9.0a3. That's how I have discovered the regression.

@mdickinson

This comment has been minimized.

Copy link
Member Author

mdickinson commented Feb 2, 2020

The broken code made it to 3.9.0a3.

Whoops; you're right. News entry needed, then!

@mdickinson mdickinson removed the skip news label Feb 2, 2020
mdickinson added 2 commits Feb 2, 2020
@codecov

This comment has been minimized.

Copy link

codecov bot commented Feb 2, 2020

Codecov Report

Merging #18309 into master will increase coverage by 1.07%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff             @@
##           master   #18309       +/-   ##
===========================================
+ Coverage   82.11%   83.19%    +1.07%     
===========================================
  Files        1955     1570      -385     
  Lines      588596   414126   -174470     
  Branches    44401    44402        +1     
===========================================
- Hits       483346   344525   -138821     
+ Misses      95605    59963    -35642     
+ Partials     9645     9638        -7     
Impacted Files Coverage Δ
Lib/distutils/tests/test_bdist_rpm.py 30.00% <0.00%> (-65.00%) ⬇️
Lib/distutils/command/bdist_rpm.py 7.63% <0.00%> (-56.88%) ⬇️
Lib/test/test_urllib2net.py 76.92% <0.00%> (-13.85%) ⬇️
Lib/test/test_smtpnet.py 78.57% <0.00%> (-7.15%) ⬇️
Lib/ftplib.py 63.85% <0.00%> (-6.06%) ⬇️
Lib/test/test_ftplib.py 87.11% <0.00%> (-4.72%) ⬇️
Tools/scripts/db2pickle.py 17.82% <0.00%> (-3.97%) ⬇️
Tools/scripts/pickle2db.py 16.98% <0.00%> (-3.78%) ⬇️
Lib/test/test_socket.py 71.94% <0.00%> (-3.77%) ⬇️
Lib/test/test_asyncio/test_base_events.py 91.84% <0.00%> (-3.30%) ⬇️
... and 435 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b94737a...2f0db20. Read the comment docs.

@@ -13,6 +13,12 @@
__all__ = ['Fraction']


def _gcd(a, b):

This comment has been minimized.

Copy link
@corona10

corona10 Feb 2, 2020

Member

Looks good, what about declared this function as the nested function?

This comment has been minimized.

Copy link
@corona10

corona10 Feb 2, 2020

Member

In this case, we can skip the news :)

This comment has been minimized.

Copy link
@corona10

corona10 Feb 2, 2020

Member
-def _gcd(a, b):
-    # Supports non-integers for backward compatibility.
-    while b:
-        a, b = b, a%b
-    return a
-
 # Constants related to the hash implementation;  hash(x) is based
 # on the reduction of x modulo the prime _PyHASH_MODULUS.
 _PyHASH_MODULUS = sys.hash_info.modulus
@@ -98,6 +92,11 @@ class Fraction(numbers.Rational):
         """
         self = super(Fraction, cls).__new__(cls)

+        def _gcd(a, b):
+            while b:
+                a, b = b, a%b
+            return a
+
         if denominator is None:
             if type(numerator) is int:
                 self._numerator = numerator

This comment has been minimized.

Copy link
@mdickinson

mdickinson Feb 2, 2020

Author Member

Looks good, what about declared this function as the nested function?

I'd prefer to revert to as close as possible to the previous code, which had _gcd as a module-level function.

I think we do need a news entry, because this is fixing a bug that was already made available in a release. If the bug had been introduced and then fixed without any intermediate release, then we could have skipped the news entry.

This comment has been minimized.

Copy link
@corona10

corona10 Feb 2, 2020

Member

Got it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.