[Python-Dev] New and Improved Import Hooks

Moore, Paul Paul.Moore@atosorigin.com
Tue, 3 Dec 2002 11:48:29 -0000


(I'm reading python-dev via the web, so this is a combined reply
to various posts)

First of all, let me say that I'm interested in imports from
zipfiles, as a feature. I don't have any intrinsic reason to
prefer a specific implementation over any other. I picked up Jim
Ahlstrom's patch and had a look at it simply because it seemed
the best way to help.

My view is that import.c is, indeed, very complex and difficult
code to follow. I haven't made a significant attempt to do so,
taking the view that as Jim's patch basically worked for him, I
will just look at updating things to cope with the changes in
CVS since his patch was current. (The comments in SF indicate
that the patch was nearly accepted as it stood, and just needed
updating to match current CVS).

I agree with Just's comments that a cleanup in import.c would be
useful. But I'm not in a position to do that, much as I would
like it. (One example - "universal newline" support could do with
being better localised - I just implemented the 4th copy of a
tiny chunk of code to juggle file open modes to support it).

I think that the zipfile patch is close to being acceptable. I
don't have a problem if it gets rejected, but can I make a plea
- if it does, can it be "Rejected because patch XXX does the job
better" rather than "Rejected because this can be implemented
better using feature YYY". In other words, as Martin suggests,
can any competing proposal actually *implement* zipfile imports,
so that we don't hit a new delay.

By the way, the zipfile import also implements a cacheing feature
for directory lookups. PEP 273 gives more details, including
some benchmarks, but the indications are that the cache speeds
up normal imports as well as being crucial for zipfile imports
(where directory lookups are *slow*). I can't see how the design
of Just's patch would help us implement this cache - maybe he can
comment.

Finally, while we're looking at imports and hooks, has anyone
considered Gordon McMillan's imputil replacement, as described at
http://www.mcmillan-inc.com/iu.html? I've used it to implement a
proof-of-concept zipfile import (in Python) before now, and it
was pretty simple to use. Maybe this would be a good candidate
for the standard library?

Thanks to everyone for the interest and support.
Paul.