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: x format of % operator broken in Python 3.5.2
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.5
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: PeterTom, SilentGhost, ethan.furman
Priority: normal Keywords:

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 <module>
    "%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:34adminsetgithub: 71859
2016-09-09 18:35:41ethan.furmansettitle: 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:23ethan.furmansetnosy: + ethan.furman
messages: + msg271905
2016-08-03 11:51:03SilentGhostsetstatus: open -> closed
resolution: wont fix
messages: + msg271900
2016-08-03 11:44:01PeterTomsetstatus: closed -> open
resolution: wont fix -> (no value)
messages: + msg271898
2016-08-03 11:30:53SilentGhostsetstatus: open -> closed

nosy: + SilentGhost
messages: + msg271895

resolution: wont fix
stage: resolved
2016-08-03 11:18:43PeterTomcreate