Issue 27672: x format of % operator broken in Python 3.5.2 (original) (raw)

Created on 2016-08-03 11:18 by PeterTom, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (5)
msg271894 - (view) Author: Peter Tomcsanyi (PeterTom) Date: 2016-08-03 11:18
In Python 3.4.4 (64-bit) and in many previous versions it worked like this: >>> "%02x" % 12.99 '0c' Now in Python 3.5.2 (64-bit) it shows an error: >>> "%02x" % 12.99 Traceback (most recent call last): File "<pyshell#0>", line 1, in "%02x" % 12.99 TypeError: %x format: an integer is required, not float This problem broke some of my code which uses turtle.py (which is part of the cpython distribution), but I can see similar problems also in some third party code (e.g. I can see it in canvasvg3.py). So I kindly ask for returning the 3.4-like interpretation of the x format (and o format and maybe also other formats).
msg271895 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2016-08-03 11:30
It's not an accidental change (so it's not "broken" by any definition), see issue 19995 for details.
msg271898 - (view) Author: Peter Tomcsanyi (PeterTom) Date: 2016-08-03 11:44
So it is even worse, it is an "intentional break". I will need to review a few thousands lines of code because of this. I think that breaking others' code by redefining a "built-in" operator is acceptable when changing major versions (like 2 to 3), not minor ones (3.4 to 3.5).
msg271900 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2016-08-03 11:51
I'm not suggesting your reviewing code, I've referenced issue where this change was discussed and implemented so that you can familiarize yourself with the arguments. Your code worked by accident, the workaround seems trivial. If you wish to advance further arguments, please take them to that issue. This issue is closed and doesn't need re-opening.
msg271905 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2016-08-03 13:19
I'm not trying to rub salt in the wound, but it's a good idea (for all of us) to test our programs with "-W always" to see if any thing pops up: $ python3.4 -W always -c "'%x' % 3.14" sys:1: DeprecationWarning: automatic int conversions have been deprecated Also, this change was made because it was considered a bug.
History
Date User Action Args
2022-04-11 14:58:34 admin set github: 71859
2016-09-09 18:35:41 ethan.furman set title: x fromat of % operator broken in Python 3.5.2 -> x format of % operator broken in Python 3.5.2
2016-08-03 13:19:23 ethan.furman set nosy: + ethan.furmanmessages: +
2016-08-03 11:51:03 SilentGhost set status: open -> closedresolution: wont fixmessages: +
2016-08-03 11:44:01 PeterTom set status: closed -> openresolution: wont fix -> (no value)messages: +
2016-08-03 11:30:53 SilentGhost set status: open -> closednosy: + SilentGhostmessages: + resolution: wont fixstage: resolved
2016-08-03 11🔞43 PeterTom create