Message6008

Author akruis
Recipients akruis
Date 2010-08-24.07:38:34
SpamBayes Score 8.3266727e-16
Marked as misclassified No
Message-id <1282635518.82.0.872934736028.issue1648@psf.upfronthosting.co.za>
In-reply-to
Content
Hi,

Pep 328 introduces besides other features the notation of relative imports (from with dots) and "from __future__ import absolute_import". Unfortunately the jython implementation of both features is either incomplete (#1516) or broken (#1495).

Fortunately I need a fully functional pep328 implementation for my current project and could spend some time on this issue. 
The attached patch adds a new regression test "Lib/test/test_import_pep328.py". This test is pure python and also runs with c-python ("python25 test_import_pep328.py"). With c-python 2.5 the test runs OK. With the current (r7101) jython, several tests fail.

test_import_pep328.py contains two test classes: The first tests, how the parser and compiler convert import statements ("import" and "from ... import ...") into calls of the __import__ function. The second class tests, how the __import__ function handles various import situations utilizing the meta_path-hook to observe the inner workings of __import__.

I found the following defects.

- A coding bug in GrammarActions causing NPE

- Relative imports (from with at least one leading dot) call __import__ with a name containing the dots. That's probably wrong, because the information about the dots is in the level parameter of import and c-python strips the dots.

- CodeCompiler lacks support for absolute imports for "from A import *" and "import A".

- In case of an relative or absolute import (the current default), C-python calls __import__ with 4 arguments only to be compatible with previous implementations. Jython always uses the 5 argument form of __import__

- For relative imports, the computation of the full module name is broken.

Of course the test_import_pep328.py is intended to become a part of the jython test suite. I'm not sure, if I need to sign a PSF contributors agreement for it. If so, please let me know.
History
Date User Action Args
2010-08-24 07:38:39akruissetrecipients: + akruis
2010-08-24 07:38:38akruissetmessageid: <1282635518.82.0.872934736028.issue1648@psf.upfronthosting.co.za>
2010-08-24 07:38:38akruislinkissue1648 messages
2010-08-24 07:38:37akruiscreate