[Python-Dev] Import semantics

Guido van Rossum guido at python.org
Wed Jul 5 10:12:53 CEST 2006


On 6/25/06, Frank Wierzbicki <fwierzbicki at gmail.com> wrote:
> Sorry for the untrimmed conversation, but I've cc'ed jython-dev, my
> comments are at the bottom.
>
> On 6/12/06, Guido van Rossum <guido at python.org> wrote:
> > On 6/12/06, Samuele Pedroni <pedronis at strakt.com> wrote:
> > > Fabio Zadrozny wrote:
> > > > Python and Jython import semantics differ on how sub-packages should be
> > > > accessed after importing some module:
> > > >
> > > > Jython 2.1 on java1.5.0 (JIT: null)
> > > > Type "copyright", "credits" or "license" for more information.
> > > >  >>> import xml
> > > >  >>> xml.dom
> > > > <module xml.dom at 10340434>
> > > >
> > > > Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on
> > > > win32
> > > > Type "help", "copyright", "credits" or "license" for more information.
> > > >  >>> import xml
> > > >  >>> xml.dom
> > > > Traceback (most recent call last):
> > > >   File "<stdin>", line 1, in ?
> > > > AttributeError: 'module' object has no attribute 'dom'
> > > >  >>> from xml.dom import pulldom
> > > >  >>> xml.dom
> > > > <module 'xml.dom' from 'C:\bin\Python24\lib\xml\dom\__init__.pyc'>
> > > >
> > > > Note that in Jython importing a module makes all subpackages beneath it
> > > > available, whereas in python, only the tokens available in __init__.py
> > > > are accessible, but if you do load the module later even if not getting
> > > > it directly into the namespace, it gets accessible too -- this seems
> > > > more like something unexpected to me -- I would expect it to be
> > > > available only if I did some "import xml.dom" at some point.
> > > >
> > > > My problem is that in Pydev, in static analysis, I would only get the
> > > > tokens available for actually imported modules, but that's not true for
> > > > Jython, and I'm not sure if the current behaviour in Python was expected.
> > > >
> > > > So... which would be the right semantics for this?
> > >
> > > the difference in Jython is deliberate. I think the reason was to mimic
> > > more the Java style for this, in java fully qualified names always work.
> > > In jython importing the top level packages is enough to get a similar
> > > effect.
> > >
> > > This is unlikely to change for backward compatibility reasons, at least
> > > from my POV.
> >
> > IMO it should do this only if the imported module is really a Java
> > package. If it's a Python package it should stick to python semantics
> > if possible.
> >
> > --
> > --Guido van Rossum (home page: http://www.python.org/~guido/)
>
> This is a tough one since the BDFL and Samuele disagree here.  Perhaps
> we should document the Java import behavior as permanent, but document
> the Python imports in Jython as being deprecated but available until
> some future release?  I believe we would keep it at least through
> Jython 2.3.

Hi Frank,

Have you and/or the Jython community made up your mind about this? The
thread seems to have disappeared after you posted (or perhaps it
continued only on jython-dev, which I don't read?).

Also, I just realized that you're the new Jython maintainer. Is *that*
official? I'd like to offer you my congratulations, and, more
importantly, any support you might need. I find Jython an important
part for Python's long-term stategy. I'm asked occasionally what the
status of Jython is; people point out that the last release was 2.1
many years ago and the website has no news since early 2005; thy're
afraid that Jython is dying and that it's not a viable choice for new
projects. I'm very happy to be able to tell them that soon there will
be a 2.3 release and yes there *is* continued support... So if you
need anything from me or from the PSF, please let me know!

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list