Patches item #1491866, was opened at 2006-05-19 23:27 Message generated for change (Comment added) made by sonderblade You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1491866&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Core (C code) Group: Python 2.5 Status: Open Resolution: None Priority: 5 Private: No Submitted By: Heiko Wundram (hwundram) Assigned to: Nobody/Anonymous (nobody) Summary: Complex representation Initial Comment: As per request on c.l.p: http://groups.google.de/group/comp.lang.python/browse_thread/thread/26c93fefefd3a100/bf1924ce28fac1ac?hl=de#bf1924ce28fac1ac I've implemented a small patch to change the output of repr(x) for complex variables, so that complex(repr(x)) works for any complex x. This changes the output of repr(x) to '<r>+<i>j' without brackets, but leaves the string output untouched. This change of behaviour would be in line with int(repr(x)) and float(repr(x)) being defined for any int or float x, repectively. I don't know whether this patch is sensible, and whether it breaks any current code, because (for example) eval("5*%r" % (1+2j,)) won't work properly anymore, or whether it'd be more sensible to change the complex constructor to also accept a bracketed expression. I'll attach a patch to do the latter later. ---------------------------------------------------------------------- Comment By: Bj�rn Lindqvist (sonderblade) Date: 2007-03-08 01:04 Message: Logged In: YES user_id=51702 Originator: NO I have applied this patch in 2.6 and it seem to work as intended. The test_complex.py unit tests all pass. I guess the change could be useful if you are are serializing and desearializing lists of complex numbers. I think it should be applied. ---------------------------------------------------------------------- Comment By: Heiko Wundram (hwundram) Date: 2006-05-20 13:20 Message: Logged In: YES user_id=791932 The attached patch is a revised version of the patch to the complex constructor to accept bracketed string expressions, which also adds documentation changes (whatsnew25). Anyway, I personally also find this to be the "better" way, so I've removed the repr-changing patch. And, calling it a bug was by accident: I should've rather called it tracker item, which is pretty synonymous for me. ---------------------------------------------------------------------- Comment By: Terry J. Reedy (tjreedy) Date: 2006-05-20 07:24 Message: Logged In: YES user_id=593130 (The current behavior is not a bug, nor is this patch submission a bug report, so let us omit that word.) I think your example suggests why complexes are printed in parens, so I think enhancing complex() to accept such is the better approach if any change is to be made. ---------------------------------------------------------------------- Comment By: Heiko Wundram (hwundram) Date: 2006-05-20 00:28 Message: Logged In: YES user_id=791932 The second patch (python-complex-constructor.diff) changes the constructor to accept bracketed complex numbers which are enclosed in a single bracket. I'd rather say this is the better appropach to have complex(repr(x)) work, but I leave both patches attached to this bug. The latter patch also creates test cases testing for formatting errors with bracketed expressions. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1491866&group_id=5470
_______________________________________________ Patches mailing list Patches@python.org http://mail.python.org/mailman/listinfo/patches