Message11723
Oh great: automatic imports. This is better than plain old Python! But seriously ... I confirm the observation and agree this is incorrect behaviour.
PS issue2654> dir test_mod
...
-a---- 27/02/2018 21:55 270 Bad.class
-a---- 27/02/2018 21:50 69 Bad.java
-a---- 27/02/2018 07:56 28 hello.py
-a---- 27/02/2018 07:56 28 __init__.py
PS issue2654> jython
Jython 2.7.2a1+ (default:d74f8c2cd56f, Feb 24 2018, 17:18:53)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_151
Type "help", "copyright", "credits" or "license" for more information.
>>> import test_mod
Executed: test_mod\__init__.py
>>> dir(test_mod)
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__']
>>> test_mod.Bad.x ### This magical import we want (I think)
42
>>> dir(test_mod)
['Bad', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__']
>>> type(test_mod.hello) ### This magical import is not Python :(
Executed: test_mod\hello.py
<type 'module'>
It's not as bad as at first I thought. It would still have my vote to be fixed before 2.7.2 goes out.
The business of package/module import is difficult enough in plain Python. We add Java packages to the mix, which are syntactically similar and semantically different, so it is bound to be difficult. The first thing is to be clear what behaviour we want. The Jython Book has something useful to say here:
http://www.jython.org/jythonbook/en/1.0/ModulesPackages.html#sys-path
The word "disastrous" should give us pause.
On the other hand, the Java semantics are a lot like Python 3 namespace packages (PEP 420). There the first __init__.py still defines a regular package exclusively at that location. |
|
Date |
User |
Action |
Args |
2018-02-27 22:34:42 | jeff.allen | set | messageid: <1519770882.3.0.467229070634.issue2654@psf.upfronthosting.co.za> |
2018-02-27 22:34:42 | jeff.allen | set | recipients:
+ jeff.allen, fwierzbicki, jamesmudd |
2018-02-27 22:34:42 | jeff.allen | link | issue2654 messages |
2018-02-27 22:34:41 | jeff.allen | create | |
|