Skip to content

2to3 does not convert __builtins__.file #51411

Closed

Description

@joeamenta
mannequin
BPO 7162
Nosy @amauryfa, @benjaminp, @merwok, @berkerpeksag
Superseder
  • bpo-45544: Close 2to3 issues and list them here
  • Files
  • issue7162.patch
  • issue7162-2.patch
  • issue7162-3.patch: Modified issue7162-2.patch to use is_probably_builtin to check that file()
  • 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 = 'https://github.com/benjaminp'
    closed_at = <Date 2021-10-20.22:44:58.765>
    created_at = <Date 2009-10-17.21:29:37.812>
    labels = ['type-bug', 'expert-2to3']
    title = '2to3 does not convert __builtins__.file'
    updated_at = <Date 2021-10-20.22:44:58.764>
    user = 'https://bugs.python.org/joeamenta'

    bugs.python.org fields:

    activity = <Date 2021-10-20.22:44:58.764>
    actor = 'iritkatriel'
    assignee = 'benjamin.peterson'
    closed = True
    closed_date = <Date 2021-10-20.22:44:58.765>
    closer = 'iritkatriel'
    components = ['2to3 (2.x to 3.x conversion tool)']
    creation = <Date 2009-10-17.21:29:37.812>
    creator = 'joe.amenta'
    dependencies = []
    files = ['16392', '16393', '16490']
    hgrepos = []
    issue_num = 7162
    keywords = ['patch']
    message_count = 6.0
    messages = ['94190', '100196', '100197', '100598', '100612', '100627']
    nosy_count = 6.0
    nosy_names = ['amaury.forgeotdarc', 'benjamin.peterson', 'eric.araujo', 'rcoyner', 'joe.amenta', 'berker.peksag']
    pr_nums = []
    priority = 'normal'
    resolution = 'wont fix'
    stage = 'resolved'
    status = 'closed'
    superseder = '45544'
    type = 'behavior'
    url = 'https://bugs.python.org/issue7162'
    versions = ['Python 3.4', 'Python 3.5']

    Activity

    1. joeamenta commented on Oct 17, 2009

      joeamentamannequin
      MannequinAuthor

      Step to reproduce:

      $ echo 'file("/some/file")' | python `which 2to3` -

      (replace python with whichever python executable version you wish to
      use, e.g. ~/python-trunk/python or /usr/local/bin/python3.2 )

      Expected result:
      Anything referring to the fact that the "file" type no longer exists in
      python 3.x, whether it be a warning or a refactoring.

      Actual result:
      RefactoringTool: No files need to be modified.

      Just a report for now, I don't have the time to write a patch.

    2. rcoyner commented on Feb 28, 2010

      rcoynermannequin
      Mannequin

      Patch attached. Unit test and documentation included.

      COMMITMSG:

      Adds a new fixer to lib2to3 which replaces the deprecated builtin "file" with "open".

    3. rcoyner commented on Feb 28, 2010

      rcoynermannequin
      Mannequin

      Woops. Removed the extra comments. Updated patch attached.

    4. amauryfa commented on Mar 7, 2010

      @amauryfa
      Contributor

      Unfortunately this patch would also replace legitimate uses of a "file" function.

    5. rcoyner commented on Mar 7, 2010

      rcoynermannequin
      Mannequin

      I thought the whole point was that file[1] was removed in 3.0[2]? Or, are you saying that if somebody overloaded file with def file(...)? If that is the case would it be reasonable to check like this?

      >>> file in list(__builtins__.__dict__.values())
      True
      >>> def file():
      ...     pass
      ... 
      >>> file in list(__builtins__.__dict__.values())
      False
      >>> 

      [1] - http://docs.python.org/library/functions.html?highlight=file#file
      [2] - http://docs.python.org/3.1/whatsnew/3.0.html#builtins

    6. joeamenta commented on Mar 8, 2010

      joeamentamannequin
      MannequinAuthor

      Yes, the idea was that it doesn't seem outlandish for someone to do:
      def file(something):
      do_stuff()

      You can use lib2to3.fixer_util.is_probably_builtin for this... modified the patch and attached.

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

    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