[Python-Dev] New and Improved Import Hooks

Just van Rossum just@letterror.com
Tue, 3 Dec 2002 15:52:18 +0100


Neal Norwitz wrote:

> On Tue, Dec 03, 2002 at 11:48:29AM -0000, Moore, Paul wrote:
> > 
> > My view is that import.c is, indeed, very complex and difficult
> > code to follow. I agree with Just's comments that a cleanup in
> > import.c would be useful. 
> 
> I agree with both of these statements.  I have reviewed the patch.
> While it's quite involved, I don't think it's worth rejecting.
> I would really like to see a cleanup, though.

I'm working hard on a zipimport module that uses sys.import_hooks. It's going to
be SO much cleaner than the existing zip import patch.

> Rejecting the patch would be worthwhile if the interface would need to
> change after incorporating this patch.  I don't believe this is the
> case.  Whether this patch is accepted or not wouldn't change future
> patches that Just wants to incorporate.

I personally reject the patch because it modifies import.c beyond repair. Once
this stuff is in, there's NO way we can go back without a huge effort, meaning
it won't happen. It adds a whole directory listing caching scheme that is a)
totally unneeded and b) has (IMO) _nothing_ to do with zip importing per se.
That ExternalNames/External names stuff? I don't understand why it is needed
just to enable zip imports. It's a lot of stuff!

> > 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".
> 
> Agreed.

And that's ecxactly what I intend to say in a couple of days if not sooner.

[ ... ]
> If Just incorporates his import patch, perhaps the zipfile code could
> be refactored to use the more generic framework.  I don't view these
> two patches as mutually exclusive. 

I *totally* do.

> If all of these issues are
> addressed, the resulting code could be clearer, even if intermediate
> versions are not.

A rewrite now is MUCH easier than cleaning it up later. It's going to be much
less code. Wait and see.

Just