FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-44258: support PEP 515 for Fraction's initialization from string by skirpichev · Pull Request #26422 · python/cpython · GitHub

/ cpython Public

bpo-44258: support PEP 515 for Fraction's initialization from string - #26422

Merged
mdickinson merged 11 commits into
python:mainfrom
skirpichev:fix-44258
Jun 7, 2021
Merged

bpo-44258: support PEP 515 for Fraction's initialization from string#26422
mdickinson merged 11 commits into
python:mainfrom
skirpichev:fix-44258

Conversation

skirpichev commented May 28, 2021
edited
Loading

Copy link
Copy Markdown
Member

mdickinson self-requested a review May 28, 2021 14:56
Comment thread Lib/fractions.py Outdated
Comment thread Lib/fractions.py Outdated
Comment thread Lib/fractions.py Outdated
denom = m.group('denom')
if denom:
denominator = int(denom)
denominator = m.group('den')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'd suggest reverting this set of changes; IIUC they're not needed for this PR, and I don't see any particular advantage to the rename. (In fact, I prefer the version where we don't have the same local name referring to both a string and an int.)

skirpichev May 30, 2021
edited
Loading

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I don't see any particular advantage to the rename.

Naming of patterns seems to be more consistent in this case: num/den vs num/denom.

But you are right, this is not related to the PR. I'll revert.

I prefer the version where we don't have the same local name referring to both a string and an int

I don't think there are. We have den/denom for strings and denominator - which is an integer.

This patch may be better:

diff --git a/Lib/fractions.py b/Lib/fractions.py
index 180cd94c28..1268b6bd27 100644
--- a/Lib/fractions.py
+++ b/Lib/fractions.py
@@ -26,7 +26,7 @@
     (?=\d|\.\d)                           # lookahead for digit or .digit
     (?P<num>\d*|\d+(_\d+)*)               # numerator (possibly empty)
     (?:                                   # followed by
-       (?:/(?P<denom>\d+(_\d+)*))?        # an optional denominator
+       (?:/(?P<den>\d+(_\d+)*))?          # an optional denominator
     |                                     # or
        (?:\.(?P<decimal>d*|\d+(_\d+)*))?  # an optional fractional part
        (?:E(?P<exp>[-+]?\d+(_\d+)*))?     # and optional exponent
@@ -115,9 +115,9 @@ def __new__(cls, numerator=0, denominator=None, *, _normalize=True):
                     raise ValueError('Invalid literal for Fraction: %r' %
                                      numerator)
                 numerator = int(m.group('num') or '0')
-                denom = m.group('denom')
-                if denom:
-                    denominator = int(denom)
+                den = m.group('den')
+                if den:
+                    denominator = int(den)
                 else:
                     denominator = 1
                     decimal = m.group('decimal')

Copy link
Copy Markdown
Member Author

Artifact uploading failure seems to be unrelated.

mdickinson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks for the updates. LGTM! Please could you add a doc update? I think we need a .. versionchanged entry in the main docs, and a what's new entry.

Copy link
Copy Markdown
Member Author

Please could you add a doc update? I think we need a .. versionchanged entry in the main docs, and a what's new entry.

I did. Lets see how it's...

mdickinson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM. One suggestion for rewording the .. versionchanged note.

Comment thread Doc/library/fractions.rst Outdated

skirpichev commented May 31, 2021 via email

Copy link
Copy Markdown
Member Author

mdickinson merged commit 89e50ab into python:main Jun 7, 2021
skirpichev deleted the fix-44258 branch June 7, 2021 07:19

Copy link
Copy Markdown
Member Author

Oh, next time warn me about merging: commit message was a bit messy. If I did expect that - I would did rebase after every commit in the pr histoiry.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL