Message10130

Author dcoles
Recipients dcoles
Date 2015-06-23.17:43:52
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1435081433.74.0.235662668073.issue2372@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2015-06-23 17:43:53dcolessetrecipients: + dcoles
2015-06-23 17:43:53dcolessetmessageid: <1435081433.74.0.235662668073.issue2372@psf.upfronthosting.co.za>
2015-06-23 17:43:53dcoleslinkissue2372 messages
2015-06-23 17:43:52dcolescreate