This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Fraction constructor may accept spaces around '/'
Type: Stage:
Components: Library (Lib) Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Sergey.Kirpichev, mark.dickinson, veky
Priority: normal Keywords: patch

Created on 2021-06-08 08:29 by Sergey.Kirpichev, last changed 2022-04-11 14:59 by admin.

Files
File name Uploaded Description Edit
fraction-spaces.diff Sergey.Kirpichev, 2021-06-08 08:29
Messages (5)
msg395314 - (view) Author: Sergey B Kirpichev (Sergey.Kirpichev) * Date: 2021-06-08 08:29
Per https://bugs.python.org/msg394731 suggestion.

For instance, mpq_set_str() does support this.  Also, gmpy2.mpq().

Tentative patch attached.
msg395379 - (view) Author: Vedran Čačić (veky) * Date: 2021-06-09 06:18
Of course, I'm for it. But we have to be consistent... I was surprised to realize `complex` doesn't accept '2 + 3j' (even though it accepts '(2+3j)', and even '\n2+3j\t'). There are a lot of slippery slopes here (e.g. how about 3_j?). I think that once we allowed _ in integer literals, suddenly we could add more separation between digits than around them in many contexts, and that just seems wrong.
msg395381 - (view) Author: Sergey B Kirpichev (Sergey.Kirpichev) * Date: 2021-06-09 06:34
On Wed, Jun 09, 2021 at 06:18:22AM +0000, Vedran Čačić wrote:
> I was surprised to realize `complex` doesn't accept '2 + 3j'

Good catch, probably that should be allowed too.

> e.g. how about 3_j?

The PEP 515 added '_' as a separator between digits.  But the
imaginary unit is not a digit.  For same reason '1_/_2' shouldn't
be allowed for the Rational constructor.  (Unfortunately, the
Decimal class breaks this PEP convention as well as some other,
see issue44267.  For example, it accepts things like '1_._2'.)
msg395382 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2021-06-09 06:56
> I was surprised to realize `complex` doesn't accept '2 + 3j'

See previous discussion in #9574.
msg395384 - (view) Author: Sergey B Kirpichev (Sergey.Kirpichev) * Date: 2021-06-09 07:04
> See previous discussion in #9574.

Given this, probably spaces around '/' should be disallowed.
History
Date User Action Args
2022-04-11 14:59:46adminsetgithub: 88512
2021-06-09 07:04:43Sergey.Kirpichevsetmessages: + msg395384
2021-06-09 06:56:21mark.dickinsonsetnosy: + mark.dickinson
messages: + msg395382
2021-06-09 06:34:23Sergey.Kirpichevsetmessages: + msg395381
2021-06-09 06:18:22vekysetnosy: + veky
messages: + msg395379
2021-06-08 08:29:36Sergey.Kirpichevcreate