➜

This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
标题: 2to3 does not convert __builtins__.file
类型: behavior Stage: resolved
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 3.4, Python 3.5
process
状态: closed Resolution: wont fix
Dependencies: 后续: Close 2to3 issues and list them here
View: 45544
分配给: benjamin.peterson 抄送列表: amaury.forgeotdarc, benjamin.peterson, berker.peksag, eric.araujo, joe.amenta, rcoyner
优先级: normal 关键字: patch

Created on 2009-10-17 21:29 by joe.amenta, last changed 2022-04-11 14:56 by admin. This issue is now closed.

文件
文件名 上传时间 Description 编辑
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) 日期: 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) 日期: 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) 日期: 2010-02-28 00:48
Woops. Removed the extra comments. Updated patch attached.
msg100598 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) 日期: 2010-03-07 18:21
Unfortunately this patch would also replace legitimate uses of a "file" function.
msg100612 - (view) Author: Ryan Coyner (rcoyner) 日期: 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) 日期: 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.
历史
日期 用户 动作 参数
2022-04-11 14:56:54admin修改github: 51411
2021-10-20 22:44:58iritkatriel修改状态: open -> closed
后续: Close 2to3 issues and list them here
resolution: wont fix
stage: patch review -> resolved
2014-07-03 05:58:01berker.peksag修改抄送: + berker.peksag
2014-07-03 05:57:55berker.peksag修改versions: + Python 3.4, Python 3.5, - Python 3.1, Python 3.2, Python 3.3
2010-09-20 21:17:59eric.araujo修改抄送: + eric.araujo

versions: + Python 3.3, - Python 2.6, Python 3.0, Python 2.7
2010-08-21 03:11:35benjamin.peterson链接issue9648 superseder
2010-03-08 02:26:11joe.amenta修改文件: + issue7162-3.patch

消息: + msg100627
2010-03-07 21:24:33rcoyner修改消息: + msg100612
2010-03-07 18:21:02amaury.forgeotdarc修改抄送: + amaury.forgeotdarc, benjamin.peterson
消息: + msg100598

assignee: benjamin.peterson
stage: patch review
2010-02-28 00:48:34rcoyner修改文件: + issue7162-2.patch

消息: + msg100197
2010-02-28 00:46:17rcoyner修改文件: + issue7162.patch

抄送: + rcoyner
消息: + msg100196

keywords: + patch
2009-10-18 04:10:19joe.amenta修改type: behavior
2009-10-17 21:29:37joe.amenta创建