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: Bug in command-line module launcher
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 2.6
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, eric.araujo, ncoghlan, pakal, r.david.murray
Priority: low Keywords: patch

Created on 2010-01-30 15:59 by pakal, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test_rsFileLocking.py pakal, 2010-01-30 15:59 Module buggy when launched via -m option
py26_pkgutil_compile.patch pakal, 2010-02-01 19:44 review
Messages (7)
msg98566 - (view) Author: Pascal Chambon (pakal) * Date: 2010-01-30 15:59
I have a weird behaviour of the interpreter on my python2.6 win32 install : if I launch as __main__ the file joined below, like "python test_rsFileLocking.py", all works fine.
But if I put it in my PYTHONPATH (or current working directory), and launch it via the "-m" option of python.exe, I get this unexplanatory traceback below.
How comes the syntax analyser is not the same in both cases ? I don't what what, in this file, could give syntax errors in the latter case...


C:\Users\Pakal\Desktop\release26-maint\PCbuild>python.exe -m rstest.test_rsFileLocking
Traceback (most recent call last):
  File "C:\Users\Pakal\Desktop\release26-maint\lib\runpy.py", line 104, in _run_module_as_main
    loader, code, fname = _get_module_details(mod_name)
  File "C:\Users\Pakal\Desktop\release26-maint\lib\runpy.py", line 85, in _get_module_details
    code = loader.get_code(mod_name)
  File "C:\Users\Pakal\Desktop\release26-maint\lib\pkgutil.py", line 275, in get_code
    self.code = compile(source, self.filename, 'exec')
  File "C:\Users\Pakal\Desktop\RockSolidTools\rstest\test_rsFileLocking.py", line 391

SyntaxError: invalid syntax
msg98569 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-01-30 16:47
This fails on 2.6 maint but works on trunk.  There have been several improvements to the way that that compile works in trunk, and one of those fixed the problem that you are seeing.  The source of the problem is the final line in the source file containing nothing but whitespace.  I can't find the bug/revision that fixed this, but I suspect it depends on issue 7468, which Benjamin says is not a backport candidate.  

Since the limitation on compile on 2.6 is documented (see issue 4262), this would be considered a runpy bug if someone was moved to fix it in 2.6.
msg98575 - (view) Author: Pascal Chambon (pakal) * Date: 2010-01-30 20:15
Allright, I guess in these conditions this bugs doesn't require a patch B-)
Thanks for the details.
msg98595 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-01-31 03:06
I meant issue 7268 in my previous message.
msg98601 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2010-01-31 03:35
Since import and direct execution will cope with files that don't end with a blank line, changing the first argument to "source + '\n'" in the pkgutil compile call seems like a reasonable workaround for the limitation in the 2.6 compile function.
msg98679 - (view) Author: Pascal Chambon (pakal) * Date: 2010-02-01 19:44
Here is the patch you mentionned, it fixes my problem and seems unharmful indeed.

The little problem is, I've not found related tests (test_pkgutil doesn't deal with the importer part) to ad little checks around compile().

Is that patch worth commiting anyway ?
msg153841 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2012-02-21 03:14
Sorry, 2.6 only gets security fixes now, closing.  Thanks for the report anyway!
History
Date User Action Args
2022-04-11 14:56:57adminsetgithub: 52061
2012-02-21 03:14:45eric.araujosetstatus: open -> closed

nosy: + eric.araujo
messages: + msg153841

resolution: out of date
stage: test needed -> resolved
2010-02-01 19:44:34pakalsetfiles: + py26_pkgutil_compile.patch
keywords: + patch
messages: + msg98679
2010-01-31 03:35:13ncoghlansetmessages: + msg98601
2010-01-31 03:06:06r.david.murraysetmessages: + msg98595
2010-01-30 20:15:03pakalsetmessages: + msg98575
2010-01-30 16:47:23r.david.murraysetpriority: low

type: compile error -> behavior
title: Bug of command-line module launcher -> Bug in command-line module launcher
nosy: + r.david.murray, ncoghlan, benjamin.peterson

messages: + msg98569
stage: test needed
2010-01-30 15:59:13pakalcreate