[issue44258] Support PEP 515 for Fraction's initialization from string

2021-06-07 Thread Mark Dickinson


Change by Mark Dickinson :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed
type:  -> enhancement

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44258] Support PEP 515 for Fraction's initialization from string

2021-06-07 Thread Mark Dickinson


Mark Dickinson  added the comment:


New changeset 89e50ab36fac6a0e7f1998501f36fcd2872a6604 by Sergey B Kirpichev in 
branch 'main':
bpo-44258: support PEP 515 for Fraction's initialization from string (GH-26422)
https://github.com/python/cpython/commit/89e50ab36fac6a0e7f1998501f36fcd2872a6604


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44258] Support PEP 515 for Fraction's initialization from string

2021-05-29 Thread Mark Dickinson


Mark Dickinson  added the comment:

> How about '1_/_2'?

I'd rather keep it consistent with the rules for int: that is, if I split on 
`'/'`, I'd expect the pieces to be parseable by `int`.

As for spaces around the `/`, let's make that a separate issue.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44258] Support PEP 515 for Fraction's initialization from string

2021-05-29 Thread Vedran Čačić

Vedran Čačić  added the comment:

How about '1_/_2'? I think making / more separated adds value... though of 
course, someone will ask about '1 / 2' next. :-)

--
nosy: +veky

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44258] Support PEP 515 for Fraction's initialization from string

2021-05-28 Thread Sergey B Kirpichev


Sergey B Kirpichev  added the comment:

On Fri, May 28, 2021 at 06:48:14AM +, Mark Dickinson wrote:
> So yes please to the PR. There should be tests that check that only the
> underscore rules allowed by `int` and the others are supported: e.g.,
> `Fraction("1__2")`, and `Fraction("1_2_")` should be errors.

Ok, I did.

In the initial version I catch int()'s exceptions to
return a correct exception details.  Maybe it's better to fix
the regexp instead (don't match "wrong" strings).  I think
this might be more complicated for readers...

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44258] Support PEP 515 for Fraction's initialization from string

2021-05-28 Thread Sergey B Kirpichev


Change by Sergey B Kirpichev :


--
pull_requests: +25017
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/26422

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44258] Support PEP 515 for Fraction's initialization from string

2021-05-28 Thread Mark Dickinson


Mark Dickinson  added the comment:

+1 to the idea: `Decimal`, `float`, `complex` and `int` all understand the 
underscores; there's no good reason for `Fraction` not to.

So yes please to the PR. There should be tests that check that only the 
underscore rules allowed by `int` and the others are supported: e.g., 
`Fraction("1__2")`, and `Fraction("1_2_")` should be errors.

--
nosy: +mark.dickinson

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44258] Support PEP 515 for Fraction's initialization from string

2021-05-27 Thread Sergey B Kirpichev


New submission from Sergey B Kirpichev :

Right now:
>>> from fractions import Fraction as F
>>> F(1_2_3, 3_2_1)
Fraction(41, 107)

but

>>> F('1_2_3/3_2_1')
Traceback (most recent call last):
  File "", line 1, in 
  File "/home/sk/src/cpython/Lib/fractions.py", line 115, in __new__
raise ValueError('Invalid literal for Fraction: %r' %
ValueError: Invalid literal for Fraction: '1_2_3/3_2_1'

or even this (should be consistent with int constructor, isn't?):
>>> F('1_2_3')
Traceback (most recent call last):
  File "", line 1, in 
  File "/home/sk/src/cpython/Lib/fractions.py", line 115, in __new__
raise ValueError('Invalid literal for Fraction: %r' %
ValueError: Invalid literal for Fraction: '1_2_3'

Tentative patch attached.  Let me know if this does make sense as a PR.

--
components: Library (Lib)
files: fractions-from-str.diff
keywords: patch
messages: 394633
nosy: Sergey.Kirpichev
priority: normal
severity: normal
status: open
title: Support PEP 515 for Fraction's initialization from string
versions: Python 3.11
Added file: https://bugs.python.org/file50069/fractions-from-str.diff

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com