Issue 20731: Python 3.3.4: SyntaxError with correct source code encoding # -- coding: latin-1 -- (original) (raw)

process

Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, OPi, georg.brandl, koobs, larry, loewis, miwa, python-dev, r.david.murray, serhiy.storchaka, vstinner
Priority: release blocker Keywords: patch

Created on 2014-02-22 19:20 by OPi, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test.py OPi,2014-02-22 19:20
test1.py miwa,2014-02-24 07:12
issue20731.patch serhiy.storchaka,2014-02-24 09:08 review
Messages (15)
msg211942 - (view) Author: 🌳 Olivier Pirson β€” OPi πŸ‡§πŸ‡ͺπŸ‡«πŸ‡·πŸ‡¬πŸ‡§ 🐧 πŸ‘¨β€πŸ’» πŸ‘¨β€πŸ”¬ (OPi) Date: 2014-02-22 19:20
The test program: #!/usr/bin/env python # -*- coding: latin-1 -*- print('test') is correct in Python 3.3.3, but cause this error with Python 3.3.4: File "./test.py", line 3 - ^ SyntaxError: invalid syntax I use Windows 7, with bash (of Cygwin) and Python 3.3.4 (v3.3.4:7ff62415e426, Feb 10 2014, 18:13:51) [MSC v.1600 64 bit (AMD64)] on win32
msg211961 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-02-22 21:43
For whatever it's worth, it works fine for me on 3.3 tip on unix. The fact that it says line 3 and shows just a - is suspicious.
msg212038 - (view) Author: Martin v. LΓΆwis (loewis) * (Python committer) Date: 2014-02-23 22:50
I can reproduce the problem. I started debugging it; the issue is that, after reading the two comment lines (and detecting the source encoding), fileio_readinto gets called, which calls read(), and read() returns 17 (bytes read), with are "-\n\nprint('test')" So for some reason, the - is not consumed yet, even though it was previously read out of the file descriptor.
msg212046 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-02-23 23:54
Oops, I missed the fact that it was Benjamin that added Serhiy...Benjamin can add himself if he wants :)
msg212063 - (view) Author: Musashi Tamura (miwa) Date: 2014-02-24 07:12
You can avoid this by changing end of line to CRLF. (I don't know why) I attach a simpler test case.
msg212068 - (view) Author: 🌳 Olivier Pirson β€” OPi πŸ‡§πŸ‡ͺπŸ‡«πŸ‡·πŸ‡¬πŸ‡§ 🐧 πŸ‘¨β€πŸ’» πŸ‘¨β€πŸ”¬ (OPi) Date: 2014-02-24 08:25
All works fine with UTF-8. All works fine with latin-1 (or other) and Windows end of line. Maybe this issue is important, "First line can be executed twice": http://bugs.python.org/issue18960
msg212073 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-02-24 09:08
I can't test on Windows but may be this patch fixes the issue.
msg212074 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2014-02-24 09:08
Just in time for 3.3.5...
msg212437 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-02-28 14:49
New changeset ade5e4922a54 by Martin v. LΓΆwis in branch '3.3': Issue #20731: Properly position in source code files even if they http://hg.python.org/cpython/rev/ade5e4922a54
msg212438 - (view) Author: Martin v. LΓΆwis (loewis) * (Python committer) Date: 2014-02-28 14:52
Thanks for the patch, this is applied to 3.3 and 3.4.
msg212445 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-02-28 15:17
Regressions on buildbots, examples: http://buildbot.python.org/all/builders/x86%20OpenIndiana%203.3/builds/1458 http://buildbot.python.org/all/builders/AMD64%20Windows7%20SP1%203.3/builds/1546 http://buildbot.python.org/all/builders/AMD64%20Snow%20Leop%203.3/builds/464 etc.
msg212492 - (view) Author: Kubilay Kocak (koobs) (Python triager) Date: 2014-03-01 08:40
Regressions on FreeBSD buildbots (test_coding) http://buildbot.python.org/all/builders/AMD64%20FreeBSD%2010.0%203.3/builds/626/steps/test/logs/stdio
msg212504 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2014-03-01 15:15
This needs to be fixed for 3.3.5rc2.
msg212505 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-03-01 15:34
New changeset dcf4fbf446ca by Benjamin Peterson in branch '3.3': fix test on debug builds (closes #20731) http://hg.python.org/cpython/rev/dcf4fbf446ca
msg212520 - (view) Author: Martin v. LΓΆwis (loewis) * (Python committer) Date: 2014-03-01 21:34
Thanks for fixing it.
History
Date User Action Args
2022-04-11 14:57:59 admin set github: 64930
2014-03-29 14:19:50 Arfrever link issue21086 superseder
2014-03-01 21:34:15 loewis set messages: +
2014-03-01 15:34:34 python-dev set status: open -> closedresolution: fixedmessages: + stage: patch review -> resolved
2014-03-01 15:15:24 georg.brandl set messages: +
2014-03-01 10:27:10 Arfrever set status: closed -> openresolution: fixed -> (no value)
2014-03-01 08:40:35 koobs set nosy: + koobsmessages: +
2014-02-28 15:17:31 vstinner set nosy: + vstinnermessages: +
2014-02-28 14:52:06 loewis set status: open -> closedresolution: fixedmessages: +
2014-02-28 14:49:39 python-dev set nosy: + python-devmessages: +
2014-02-24 09:08:47 georg.brandl set messages: +
2014-02-24 09:08:00 serhiy.storchaka set files: + issue20731.patchversions: + Python 3.4keywords: + patchnosy: + larrymessages: + stage: patch review
2014-02-24 09:01:19 loewis set priority: normal -> release blockernosy: + georg.brandl
2014-02-24 08:25:10 OPi set messages: +
2014-02-24 07:58:43 serhiy.storchaka set components: + Windows
2014-02-24 07:12:30 miwa set files: + test1.pynosy: + miwamessages: +
2014-02-24 04:56:46 Arfrever set nosy: + Arfrever
2014-02-23 23:54:40 r.david.murray set nosy: - benjamin.petersonmessages: +
2014-02-23 23:53:29 r.david.murray set nosy: + benjamin.peterson
2014-02-23 22:59:15 benjamin.peterson set nosy: + serhiy.storchaka
2014-02-23 22:50:54 loewis set nosy: + loewismessages: +
2014-02-22 21:43:49 r.david.murray set nosy: + r.david.murraymessages: +
2014-02-22 19:20:15 OPi create