[Python-Dev] Write All New Import Hooks (PEP 302) in Python, Not C (original) (raw)
James C. Ahlstrom jim@interet.com
Mon, 30 Dec 2002 10:52:27 -0500
- Previous message: [Python-Dev] Mersenne Twister copyright
- Next message: [Python-Dev] Write All New Import Hooks (PEP 302) in Python, Not C
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Guido van Rossum wrote:
Python already has an import hook, namely import. PEP 302 adds three more hooks: sys.pathhooks, sys.metapath and sys.pathimporterhooks. The idea of four import hooks is already fishy. There's no pathimporterhooks; there's pathimportercache,
Ooops, sorry. I meant sys.path_importer_cache.
but that's not a new hook, it's a cache for the pathhooks hook. So I think the PEP proposes only two new hooks.
I disagree. It is publicly available in sys, and the PEP specifies it can be replaced or modified. And if you want to add a hook, it is easier to put it into sys.path_importer_cache than to add it to the list in sys.path_hooks. If you add it to sys.path_hooks, you must clear its entry in sys.path_importer_cache too.
That is a lot of external changes. That is a lot of code written in C. Um, last I looked, most of the code written in C was specific to the zip importer; only a relatively small amount of code was added to import.c (about 10%).
I agree 90% of the C would be needed anyway.
I think the proper import hook design is to write Python's import mechanism in Python along the lines of Greg's imputil.py and Gordon's iu.py.
That's a design that I have had in mind long ago, but I don't see it happening soon, because it would be a much larger overhaul of import.c.
Is there some reason you need hooks right away? A current application?
I'm not so sure. In practice, hooks are used for two things: import from other media than directories (e.g. zip files), and supporting additional filename extensions that trigger special transformations.
The PEP 302 hooks do not support the second case very well when the files with special extensions are in zip archives. Adding the hook replaces the zip hook, as all PEP 302 hooks are alternatives to each other.
JimA
- Previous message: [Python-Dev] Mersenne Twister copyright
- Next message: [Python-Dev] Write All New Import Hooks (PEP 302) in Python, Not C
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]