[Python-Dev] New universal import mechanism ( Re: [Python-checkins] python/dist/src/Python import.c,2.210,2.211) (original) (raw)
Jeff Epler jepler@unpythonic.net
Tue, 3 Dec 2002 10:03:09 -0600
- Previous message: [Python-Dev] New universal import mechanism ( Re: [Python-checkins] python/dist/src/Python import.c,2.210,2.211)
- Next message: [Python-Dev] New universal import mechanism ( Re: [Python-checkins] python/dist/src/Python import.c,2.210,2.211)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Tue, Dec 03, 2002 at 03:24:59PM +0100, Samuele Pedroni wrote:
Why then only import * should have a user-defined behavior?
What about from module import x if the importing module has already a defined x then maybe that should be also under user control? I'm surely missing something.
I don't have a good sense of why this feature is desirable, I was just suggesting how David's request might be implemented without introducing new special names.
If it was desired that 'from module import x' be able to use the special behavior, then I'd suggest leaving all as it is now, and having export, with the default behaving about like this:
def __export__(exporter, importer, names):
for name in names:
setattr(importer, name, getattr(exporter, name))
and David's export being about like this:
def __export__(exporter, importer, names):
for name in names:
attr = getattr(exporter, name)
if isinstance(attr, Multimethod):
merge_one_multimethod(exporter, name, attr)
else:
setattr(exporter, name, attr)
maybe export should be called once per name, or maybe a special value should be passed for * (instead of all)
Of course, 'from m import *' has that "do with me what you will" feeling to it, while 'from m import x' doesn't.
Jeff
- Previous message: [Python-Dev] New universal import mechanism ( Re: [Python-checkins] python/dist/src/Python import.c,2.210,2.211)
- Next message: [Python-Dev] New universal import mechanism ( Re: [Python-checkins] python/dist/src/Python import.c,2.210,2.211)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]