Skip to content

x format of % operator broken in Python 3.5.2 #71859

Closed

Description

@PeterTom
mannequin
BPO 27672
Nosy @ethanfurman

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2016-08-03.11:51:03.417>
created_at = <Date 2016-08-03.11:18:43.632>
labels = ['interpreter-core', 'type-bug']
title = 'x format of % operator broken in Python 3.5.2'
updated_at = <Date 2016-09-09.18:35:41.191>
user = 'https://bugs.python.org/PeterTom'

bugs.python.org fields:

activity = <Date 2016-09-09.18:35:41.191>
actor = 'ethan.furman'
assignee = 'none'
closed = True
closed_date = <Date 2016-08-03.11:51:03.417>
closer = 'SilentGhost'
components = ['Interpreter Core']
creation = <Date 2016-08-03.11:18:43.632>
creator = 'PeterTom'
dependencies = []
files = []
hgrepos = []
issue_num = 27672
keywords = []
message_count = 5.0
messages = ['271894', '271895', '271898', '271900', '271905']
nosy_count = 3.0
nosy_names = ['SilentGhost', 'ethan.furman', 'PeterTom']
pr_nums = []
priority = 'normal'
resolution = 'wont fix'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue27672'
versions = ['Python 3.5']

Activity

  1. PeterTom commented on Aug 3, 2016

    PeterTommannequin
    MannequinAuthor

    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).

  2. added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    type-bugAn unexpected behavior, bug, or error
    on Aug 3, 2016
  3. SilentGhost commented on Aug 3, 2016

    SilentGhostmannequin
    Mannequin

    It's not an accidental change (so it's not "broken" by any definition), see bpo-19995 for details.

  4. PeterTom commented on Aug 3, 2016

    PeterTommannequin
    MannequinAuthor

    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).

  5. SilentGhost commented on Aug 3, 2016

    SilentGhostmannequin
    Mannequin

    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.

  6. ethanfurman commented on Aug 3, 2016

    @ethanfurman
    Member

    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.

  7. changed the title [-]x fromat of % operator broken in Python 3.5.2[/-] [+]x format of % operator broken in Python 3.5.2[/+] on Sep 9, 2016
  8. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions