Issue2372

classification
Title: Wildcard import fails when used with absolute_import
Type: Severity: normal
Components: Core Versions: Jython 2.7
Milestone:
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: dcoles, jeff.allen, zyasoft
Priority: Keywords:

Created on 2015-06-23.17:43:53 by dcoles, last changed 2015-07-06.20:59:47 by zyasoft.

Messages
msg10130 (view) Author: David Coles (dcoles) Date: 2015-06-23.17:43:52
Wildcard imports from a module using `from future import absolute_import` fails to correctly find the targeted module in the same package.


Expected behaviour (under Python 2.7):

  $ PYTHONPATH=~/jython-bug python2.7 -m foo.foo
  BAR: 42


Actual behaviour:

  $ JYTHONPATH=~/jython-bug java -jar ./jython-standalone-2.7.0.jar -m foo.foo
  Traceback (most recent call last):
    File "/home/dcoles/jython-standalone-2.7.0.jar/Lib/runpy.py", line 161, in _run_module_as_main
    File "/home/dcoles/jython-standalone-2.7.0.jar/Lib/runpy.py", line 72, in _run_code
    File "/home/dcoles/jython-bug/foo/foo.py", line 2, in <module>
    from .bar import *
  ImportError: No module named bar


This can be reproduced using the following setup:


  foo/__init__.py
  ===============
  pass


  foo/foo.py
  ==========
  from __future__ import absolute_import
  from .bar import *

  if __name__ == "__main__":
      print("BAR: %s" % BAR)


  foo/bar.py
  ==========
  BAR = 42


It appears that rather than searching the libraries path, it searches the current working directory:

  # from .bar import *
  import: trying source /home/dcoles/bar
  import: trying precompiled with no source /home/dcoles/bar$py.class

  # from foo.bar import *
  import: trying source /home/dcoles/jython-bug/foo/bar
  import: trying precompiled /home/dcoles/jython-bug/foo/bar$py.class


A workaround is to switch the import style so as not to use package
relative imports.
msg10131 (view) Author: Jim Baker (zyasoft) Date: 2015-06-23.18:34:35
This has been fixed in trunk; see the recent fixes by Jeff Allen that culminated in https://hg.python.org/jython/rev/bb6cababa5bd

With these changes, Jython works as expected:

~/jythondev/jython27/dist/bin/jython -m foo.foo
BAR: 42

These fixes will be available in 2.7.1, which is still targeted for release in November.
msg10135 (view) Author: David Coles (dcoles) Date: 2015-06-27.21:47:02
Thanks for the update. Glad to hear that it's already been fixed in trunk.
History
Date User Action Args
2015-07-06 20:59:47zyasoftsetstatus: pending -> closed
2015-06-27 21:47:02dcolessetmessages: + msg10135
2015-06-23 18:34:36zyasoftsetstatus: open -> pending
nosy: + jeff.allen, zyasoft
resolution: out of date
messages: + msg10131
2015-06-23 17:43:53dcolescreate