Message11701

Author jamesmudd
Recipients jamesmudd
Date 2018-02-08.16:55:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1518108932.54.0.467229070634.issue2654@psf.upfronthosting.co.za>
In-reply-to
Content
If you have a python module eg.

test_mod/
├── hello.py      <<<<< Contains only foo = 4
└── __init__.py   <<<<< Contains only _version__ = '1.1.1'

If you import this in cpython you will not have access to hello e.g.
>>> import test_mod
>>> dir(test_mod)
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '__version__']
>>> test_mod.hello
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'hello'

Which is correct because you didn't import test_mode.hello and the __init__.py doesn't import it.

In Jython (master)

>>> import test_mod
>>> dir(test_mod)
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '__version__'] <<<<< Looks good at this point
>>> test_mod.hello
<module 'test_mod.hello' from '/scratch/test_mod/hello.py'> <<<<< This is wrong shouldn't be able to see hello
>>> test_mod.hello.foo
4
>>> dir(test_mod)
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '__version__', 'hello'] <<<<< And now its added  to the module

I think this happens because of a change made to fix #2455 which means if you lookup an attribute on a Pyhton module and don't find it try to import it. The bug described in that ticket is when you have a mixed Python/Java package. However i'm not sure it should have been fixed and now the behaviour is wrong for Python. To fix this I think the support for the mixed Python/Java package needs to be removed which I don't see as an issue.
History
Date User Action Args
2018-02-08 16:55:32jamesmuddsetrecipients: + jamesmudd
2018-02-08 16:55:32jamesmuddsetmessageid: <1518108932.54.0.467229070634.issue2654@psf.upfronthosting.co.za>
2018-02-08 16:55:32jamesmuddlinkissue2654 messages
2018-02-08 16:55:31jamesmuddcreate