classification
Title: 2to3 does not convert __builtins__.file
Type: behavior Stage: patch review
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 3.5, Python 3.4
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: benjamin.peterson Nosy List: amaury.forgeotdarc, benjamin.peterson, berker.peksag, eric.araujo, joe.amenta, rcoyner
Priority: normal Keywords: patch

Created on 2009-10-17 21:29 by joe.amenta, last changed 2014-07-03 05:58 by berker.peksag.

Files
File name Uploaded Description Edit
issue7162.patch rcoyner, 2010-02-28 00:46 review
issue7162-2.patch rcoyner, 2010-02-28 00:48 review
issue7162-3.patch joe.amenta, 2010-03-08 02:26 Modified issue7162-2.patch to use is_probably_builtin to check that file() review
Messages (6)
msg94190 - (view) Author: Joe Amenta (joe.amenta) Date: 2009-10-17 21:29
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.
msg100196 - (view) Author: Ryan Coyner (rcoyner) Date: 2010-02-28 00:46
Patch attached. Unit test and documentation included.

COMMITMSG:

Adds a new fixer to lib2to3 which replaces the deprecated builtin "file" with "open".
msg100197 - (view) Author: Ryan Coyner (rcoyner) Date: 2010-02-28 00:48
Woops. Removed the extra comments. Updated patch attached.
msg100598 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2010-03-07 18:21
Unfortunately this patch would also replace legitimate uses of a "file" function.
msg100612 - (view) Author: Ryan Coyner (rcoyner) Date: 2010-03-07 21:24
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
msg100627 - (view) Author: Joe Amenta (joe.amenta) Date: 2010-03-08 02:26
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.
History
Date User Action Args
2014-07-03 05:58:01berker.peksagsetnosy: + berker.peksag
2014-07-03 05:57:55berker.peksagsetversions: + Python 3.4, Python 3.5, - Python 3.1, Python 3.2, Python 3.3
2010-09-20 21:17:59eric.araujosetnosy: + eric.araujo

versions: + Python 3.3, - Python 2.6, Python 3.0, Python 2.7
2010-08-21 03:11:35benjamin.petersonlinkissue9648 superseder
2010-03-08 02:26:11joe.amentasetfiles: + issue7162-3.patch

messages: + msg100627
2010-03-07 21:24:33rcoynersetmessages: + msg100612
2010-03-07 18:21:02amaury.forgeotdarcsetnosy: + amaury.forgeotdarc, benjamin.peterson
messages: + msg100598

assignee: benjamin.peterson
stage: patch review
2010-02-28 00:48:34rcoynersetfiles: + issue7162-2.patch

messages: + msg100197
2010-02-28 00:46:17rcoynersetfiles: + issue7162.patch

nosy: + rcoyner
messages: + msg100196

keywords: + patch
2009-10-18 04:10:19joe.amentasettype: behavior
2009-10-17 21:29:37joe.amentacreate