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
Title: 2to3 should rewrite execfile() to open in 'rb' mode
Type: behavior Stage: resolved
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: ZackerySpytz, barry, benjamin.peterson, miss-islington, serhiy.storchaka, tshepang
Priority: normal Keywords: patch

Created on 2013-01-14 18:24 by barry, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 8569 merged ZackerySpytz, 2018-07-30 18:23
PR 9838 merged miss-islington, 2018-10-13 09:27
PR 9839 merged miss-islington, 2018-10-13 09:27
PR 9890 merged ZackerySpytz, 2018-10-15 11:25
Messages (7)
msg179964 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2013-01-14 18:24
In this distribute bug I describe a problem when pip installing mimeparse, which has a setup.py with a BOM.  distribute uses execfile() which gets fixed in Python 3 to use a combination of compile(open()) as the fixer.

https://bitbucket.org/tarek/distribute/issue/349/dont-rely-on-2to3-to-properly-rewrite

I think the problem is that the fixer opens the file in text mode, which leaves the BOM as a bogus first character, causing the SyntaxError.  Instead, if the fixer opened the file in binary mode, then the BOM would be handled correctly by compile().
msg223226 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-07-16 15:52
Can we have a response to this please.
msg327567 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-10-12 07:18
`exec(compile(open("fn", "rb").read(), "fn", 'exec'))` will emit a resource warning because the open file is not closed explicitly.

But this is a different issue.
msg327645 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-10-13 09:27
New changeset d4d60134b29290049e28df54f23493de4f1824b6 by Serhiy Storchaka (Zackery Spytz) in branch 'master':
bpo-16965: 2to3 now rewrites execfile() to open with 'rb'. (GH-8569)
https://github.com/python/cpython/commit/d4d60134b29290049e28df54f23493de4f1824b6
msg327646 - (view) Author: miss-islington (miss-islington) Date: 2018-10-13 09:48
New changeset 22381394ad1541db0b652eed802601f62510d22f by Miss Islington (bot) in branch '3.7':
bpo-16965: 2to3 now rewrites execfile() to open with 'rb'. (GH-8569)
https://github.com/python/cpython/commit/22381394ad1541db0b652eed802601f62510d22f
msg327647 - (view) Author: miss-islington (miss-islington) Date: 2018-10-13 09:51
New changeset 950fa40eee483f7507cd825b574a018b957dd253 by Miss Islington (bot) in branch '3.6':
bpo-16965: 2to3 now rewrites execfile() to open with 'rb'. (GH-8569)
https://github.com/python/cpython/commit/950fa40eee483f7507cd825b574a018b957dd253
msg327809 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-10-16 05:46
New changeset f5e00f490ab5abfcf5e38e58bf969c7b5dcb4818 by Serhiy Storchaka (Zackery Spytz) in branch '2.7':
[2.7] bpo-16965: 2to3 now rewrites execfile() to open with rb. (GH-8569) (GH-9890)
https://github.com/python/cpython/commit/f5e00f490ab5abfcf5e38e58bf969c7b5dcb4818
History
Date User Action Args
2022-04-11 14:57:40adminsetgithub: 61169
2018-10-16 05:47:18serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-10-16 05:46:40serhiy.storchakasetmessages: + msg327809
2018-10-15 11:25:37ZackerySpytzsetpull_requests: + pull_request9253
2018-10-13 09:51:39miss-islingtonsetmessages: + msg327647
2018-10-13 09:48:22miss-islingtonsetnosy: + miss-islington
messages: + msg327646
2018-10-13 09:27:50miss-islingtonsetpull_requests: + pull_request9213
2018-10-13 09:27:43miss-islingtonsetpull_requests: + pull_request9212
2018-10-13 09:27:35serhiy.storchakasetmessages: + msg327645
2018-10-12 07:18:26serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg327567
2018-07-31 05:24:32BreamoreBoysetnosy: - BreamoreBoy
2018-07-30 18:24:15ZackerySpytzsetnosy: + ZackerySpytz

versions: + Python 3.8, - Python 3.4, Python 3.5
2018-07-30 18:23:35ZackerySpytzsetkeywords: + patch
stage: patch review
pull_requests: + pull_request8081
2014-07-16 15:52:13BreamoreBoysetversions: + Python 3.5, - Python 3.2, Python 3.3
nosy: + BreamoreBoy, benjamin.peterson

messages: + msg223226

type: behavior
2013-01-18 19:27:03tshepangsetnosy: + tshepang
2013-01-14 18:24:06barrycreate