Issue 33402: Change the fractions.Fraction class to convert to a unicode fraction string (original) (raw)

Created on 2018-05-01 22:39 by gappleto97, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 6678 open gappleto97,2018-05-01 22:40
Messages (10)
msg316026 - (view) Author: Gabe Appleton (gappleto97) * Date: 2018-05-01 22:39
Currently it has a __repr__() which returns `Fraction(x, y)`, and a __str__() which returns `x/y`. I have a ready pull request to change this to a scheme where both return unicode fractions.
msg316027 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2018-05-01 22:52
Your patch would break the usual and useful behavior of x == eval(repr(x)) >>> f = Fraction(1,2) >>> repr(f) 'Fraction(1, 2)' >>> eval(repr(f)) Fraction(1, 2) >>> f == eval(repr(f)) True Plus, I'm sure there's working code that would break as a result of this. I'd suggest having a utility function that provides the functionality that you're after.
msg316028 - (view) Author: Gabe Appleton (gappleto97) * Date: 2018-05-01 22:54
Would it be workable if I instead just changed the __str__() method? I'm willing to go either way, but I feel like it's a bit nicer to have it output a nice fraction that way.
msg316029 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2018-05-01 23:06
I'd bring it up on python-ideas, and point the discussion to this issue. I think the primary complain will be using non-ASCII characters in a function that normally doesn't return non-ASCII. But maybe people will be willing to accept it.
msg316030 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2018-05-01 23:23
I vote -1. It's cute, but I'd much rather have a consistently ascii representation of something that is easily represented in ascii.
msg316034 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2018-05-02 01:44
Strings in Python 3 are already unicode. Looking at the patch, I see a lot of fractions which display as the missing glyph white square. For example, instead of seeing 1/9, which displays perfectly everywhere, I see a mysterious box similar to □. Even when I see one, there's the visual inconsistency between fractions which display like ½ and those that display like ¹²/₄₅ which frankly just looks ugly to me. One problem is that in many fonts, the glyphs for superscript and subscript digits are a hodge-podge of sizes and styles with no consistent design. If you're going to do this, you ought to use U+2044 FRACTION SLASH rather than U+002F SOLIDUS: compare ¹²⁄₄₅ with the above. If your font is decent, and many are not, the fraction slash is tighter and allows the numerator and denominator to overlap the slash, closer to the visual look of ½. I would strongly oppose this becoming the default __str__ of fractions.
msg316050 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2018-05-02 07:17
-1 from me. Apart from anything else, the output for a general fraction looks (to my eyes) ugly in a fixed-width font: the tiny digits are harder to read, and there's too much space between successive numerator (or denominator) digits: those digits are designed for superscripts or subscripts.
msg316076 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2018-05-02 14:49
In the Monaco font, the superscripts ⁰¹²³⁴⁵⁶⁷⁸⁹ don't all line-up. The 1, 2, and 3 are lower which makes the fraction look weird.
msg316077 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-05-02 14:54
I dislike using non-ASCII characters for the default implementation. I don't think that this formatting is popular, and I expect many troubles on each platform. IMHO it's very easy to put such short function in your favorite module, or directly into your application, for your own usage. Call it my_nice_fraction_formatting() :-)
msg316080 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2018-05-02 16:08
-1. We should stop pretending this _ might_ happen ;-)
History
Date User Action Args
2022-04-11 14:58:59 admin set github: 77583
2018-05-02 16:46:27 gappleto97 set status: open -> closedresolution: rejectedstage: patch review -> resolved
2018-05-02 16:08:37 tim.peters set nosy: + tim.petersmessages: +
2018-05-02 14:54:28 vstinner set nosy: + vstinnermessages: +
2018-05-02 14:49:02 rhettinger set nosy: + rhettingermessages: +
2018-05-02 07:17:10 mark.dickinson set nosy: + mark.dickinsonmessages: +
2018-05-02 01:44:19 steven.daprano set nosy: + steven.dapranomessages: +
2018-05-01 23:23:36 r.david.murray set nosy: + r.david.murraymessages: +
2018-05-01 23:06:56 eric.smith set messages: +
2018-05-01 22:54:16 gappleto97 set messages: +
2018-05-01 22:52:33 eric.smith set nosy: + eric.smithmessages: +
2018-05-01 22:40:32 gappleto97 set keywords: + patchstage: patch reviewpull_requests: + <pull%5Frequest6372>
2018-05-01 22:39:00 gappleto97 create