Skip to content

2to3 incorrectly handles multi-line imports from __future__ #57082

Closed

Description

@Arfrever
mannequin
BPO 12873
Nosy @benjaminp, @merwok
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:46:23.585>
    created_at = <Date 2011-08-31.21:57:20.653>
    labels = ['expert-2to3']
    title = '2to3 incorrectly handles multi-line imports from __future__'
    updated_at = <Date 2021-10-20.22:46:23.584>
    user = 'https://bugs.python.org/Arfrever'

    bugs.python.org fields:

    activity = <Date 2021-10-20.22:46:23.584>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-10-20.22:46:23.585>
    closer = 'iritkatriel'
    components = ['2to3 (2.x to 3.x conversion tool)']
    creation = <Date 2011-08-31.21:57:20.653>
    creator = 'Arfrever'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 12873
    keywords = []
    message_count = 5.0
    messages = ['143283', '143418', '143425', '143429', '253129']
    nosy_count = 5.0
    nosy_names = ['benjamin.peterson', 'eric.araujo', 'Arfrever', 'lunaryorn', 'jdekloe']
    pr_nums = []
    priority = 'normal'
    resolution = 'wont fix'
    stage = 'resolved'
    status = 'closed'
    superseder = '45544'
    type = None
    url = 'https://bugs.python.org/issue12873'
    versions = ['Python 2.7', 'Python 3.2', 'Python 3.3']

    Activity

    1. Arfrever commented on Aug 31, 2011

      Arfrevermannequin
      MannequinAuthor
      $ cat test1.py
      from __future__ import (absolute_import, division,
          print_function, unicode_literals)
      print(1, 2)
      $ cat test2.py
      from __future__ import (absolute_import, division, print_function, unicode_literals)
      print(1, 2)
      $ python2.7 -c 'import test1'
      1 2
      $ python2.7 -c 'import test2'
      1 2
      $ 2to3 test1.py test2.py
      RefactoringTool: Skipping implicit fixer: buffer
      RefactoringTool: Skipping implicit fixer: idioms
      RefactoringTool: Skipping implicit fixer: set_literal
      RefactoringTool: Skipping implicit fixer: ws_comma
      RefactoringTool: Refactored test1.py
      --- test1.py    (original)
      +++ test1.py    (refactored)
      @@ -1,4 +1,4 @@
       from __future__ import (absolute_import, division,
           print_function, unicode_literals)
       
      -print(1, 2)
      +print((1, 2))
      RefactoringTool: Files that need to be modified:
      RefactoringTool: test1.py
    2. merwok commented on Sep 2, 2011

      @merwok
      Member

      I don’t understand what the bug is.

    3. Arfrever commented on Sep 2, 2011

      Arfrevermannequin
      MannequinAuthor

      If import from __future__ is written in multiple lines, then a parser internally used by 2to3 recognizes only the first line. (However Python interpreter properly supports multi-line imports from __future__.)

      test1.py contains multi-line import from __future__.
      test2.py contains single-line import from __future__.
      2to3 properly handles test2.py and improperly handles test1.py.

    4. lunaryorn commented on Sep 2, 2011

      lunaryornmannequin
      Mannequin

      More precisely, the bug is, that 2to3 refactors the "print()" invocation in "test1.py" though it shouldn't because a "print_function" future import is present at the beginning of "test1.py". The cross-check with "test2.py" shows that this is due to the multi-line future import in "test1.py" because the line-break in the import statement is the only difference between both files.

    5. jdekloe commented on Oct 17, 2015

      jdekloemannequin
      Mannequin

      still having this issue with 2to3 from python-tools-2.7.8-11 as packaged by Fedora 21.
      Any progress since 2011?

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

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions