Skip to content

2to3 zip fixer doesn't fix for loops. #64941

Closed

Description

@drj11
mannequin
BPO 20742
Nosy @benjaminp, @drj11
Superseder
  • bpo-45544: Close 2to3 issues and list them here
  • 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 2021-10-20.22:45:21.073>
    created_at = <Date 2014-02-23.11:11:47.707>
    labels = ['type-bug', 'expert-2to3']
    title = "2to3 zip fixer doesn't fix for loops."
    updated_at = <Date 2021-10-20.22:45:21.073>
    user = 'https://github.com/drj11'

    bugs.python.org fields:

    activity = <Date 2021-10-20.22:45:21.073>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-10-20.22:45:21.073>
    closer = 'iritkatriel'
    components = ['2to3 (2.x to 3.x conversion tool)']
    creation = <Date 2014-02-23.11:11:47.707>
    creator = 'drj'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 20742
    keywords = []
    message_count = 3.0
    messages = ['211989', '211991', '227772']
    nosy_count = 4.0
    nosy_names = ['peter.otten', 'benjamin.peterson', 'drj', 'RobertG']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '45544'
    type = 'behavior'
    url = 'https://bugs.python.org/issue20742'
    versions = ['Python 2.7', 'Python 3.4', 'Python 3.5']

    Activity

    1. drj11 commented on Feb 23, 2014

      drj11mannequin
      MannequinAuthor

      Consider the following code:

      for z in zip([1]):pass

      2to3 does not convert the zip in this code to list(zip(...)); it does not change this code at all.

      That can be an (obscure) bug because the zip in Python 2 has different semantics from the zip in Python 3.

      The output of this program

      from __future__ import print_function
      S = []
      
      def l(c):
        for i in [0,1]:
          S.append(c)
          yield i
        S.append(c.upper())
      
      la = l('a')
      lb = l('b')
      
      for a,b in zip(la, lb):
        S.append("#")
      print(''.join(S))

      is different in Python 2 and Python 3 (when converted with 2to3, which doesn't change the program).

      In Python 2 the output is:

      ababA##

      In Python 3 the output is:

      ab#ab#A

      Obviously this example is somewhat contrived, but I have a non-contrived example involving decoding PNG images (if anyone is interested).

    2. peterotten commented on Feb 23, 2014

      peterottenmannequin
      Mannequin

      Hm, I would expect that in 99 times out of 100 the extra list(...) would be removed in a manual step following the automated conversion.

      I'd really like to see the non-contrived example with a justified use of this evil side effect ;)

    3. RobertG commented on Sep 28, 2014

      RobertGmannequin
      Mannequin

      As far as a non contrived example, see http://bugs.python.org/issue21628, which was marked as a duplicate of this bug.

      This bug is the main thing preventing me from using 2to3, so I think it is a real issue.

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

      topic-2to3type-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions