Re: [Python-3000] Interest in PEP for callbacks on module import

2007-12-10 Thread Guido van Rossum
FWIW I just modified decimal to import numbers and made Decimal inherit from Inexact and Real. No impact whatsoever. --Guido On Dec 10, 2007 1:38 PM, Greg Ewing <[EMAIL PROTECTED]> wrote: > Paul Moore wrote: > > On 10/12/2007, Jim Jewett <[EMAIL PROTECTED]> wrote: > > > >>"Don't import module X j

Re: [Python-3000] Interest in PEP for callbacks on module import

2007-12-10 Thread Greg Ewing
Paul Moore wrote: > On 10/12/2007, Jim Jewett <[EMAIL PROTECTED]> wrote: > >>"Don't import module X just for me, but *if* someone else imports it, >>then I want to do these things to/with it." > > That sounds to me exactly like the registration use case Christian mentioned: > > Register decimal.

Re: [Python-3000] Interest in PEP for callbacks on module import

2007-12-10 Thread Christian Heimes
Phillip J. Eby wrote: > The "Importing" package implements callbacks as an extension of lazy > imports, but it isn't the only way to do it. Christian's patch > implements callbacks without lazy importing, although I think it still > needs a hook (such as his previously-proposed '__lazy__' attribut

Re: [Python-3000] Interest in PEP for callbacks on module import

2007-12-10 Thread Phillip J. Eby
At 11:41 AM 12/10/2007 -0500, Jim Jewett wrote: >Is there an example where you would use post-import hooks even though >the system didn't support lazy import? The best I can come up with is >"Don't import module X just for me, but *if* someone else imports it, >then I want to do these things to/wi

Re: [Python-3000] Interest in PEP for callbacks on module import

2007-12-10 Thread Paul Moore
On 10/12/2007, Jim Jewett <[EMAIL PROTECTED]> wrote: > Is there an example where you would use post-import hooks even though > the system didn't support lazy import? The best I can come up with is > "Don't import module X just for me, but *if* someone else imports it, > then I want to do these thi

Re: [Python-3000] Interest in PEP for callbacks on module import

2007-12-10 Thread Jim Jewett
On 12/10/07, Christian Heimes <[EMAIL PROTECTED]> wrote: > Jim Jewett wrote: > > I had thought that wouldn't be run until the module was otherwise > > loaded. Are you saying that just creating the callback forces a load > > under lazy loading, but not under post-load hooks? > I was saying that t

Re: [Python-3000] Interest in PEP for callbacks on module import

2007-12-10 Thread Christian Heimes
Jim Jewett wrote: > I had thought that wouldn't be run until the module was otherwise > loaded. Are you saying that just creating the callback forces a load > under lazy loading, but not under post-load hooks? The imp.imported (or whatever we name the method) is the register method for the post

Re: [Python-3000] Interest in PEP for callbacks on module import

2007-12-09 Thread Jim Jewett
On 12/9/07, Christian Heimes <[EMAIL PROTECTED]> wrote: > Jim Jewett wrote: > > Could you give me a use-case for post-import hooks *without* lazy imports? > This thread was started with perfect valid and good use case. We want to > apply ABCs to classes of optional modules like decimal and array w

Re: [Python-3000] Interest in PEP for callbacks on module import

2007-12-09 Thread Christian Heimes
Jim Jewett wrote: > Could you give me a use-case for post-import hooks *without* lazy imports? This thread was started with perfect valid and good use case. We want to apply ABCs to classes of optional modules like decimal and array without loading the module or modifying the module. @imp.impo

Re: [Python-3000] Interest in PEP for callbacks on module import

2007-12-09 Thread Jim Jewett
On 12/9/07, Christian Heimes <[EMAIL PROTECTED]> wrote: > The touch points between post import hooks and lazy imports > are minimal. Could you give me a use-case for post-import hooks *without* lazy imports? As nearly as I can tell, either (1) The module is already loaded (and the whole infras

Re: [Python-3000] Interest in PEP for callbacks on module import

2007-12-09 Thread Christian Heimes
Phillip J. Eby wrote: > Thinking that they can, and actually producing a tested > implementation of one that does not, in fact, conflict with the > implementation of the other, are two different things. > > My concern is that I doubt that you can implement the post-import > hook without in the

Re: [Python-3000] Interest in PEP for callbacks on module import

2007-12-08 Thread Phillip J. Eby
At 12:37 PM 12/9/2007 +1300, Greg Ewing wrote: >Phillip J. Eby wrote: > > > Lazy importing is putting a module object into sys.modules, but not > > loading its contents until you attempt to get or set a module attribute. > >How is that expected to be useful? If you're not going >to access any attri

Re: [Python-3000] Interest in PEP for callbacks on module import

2007-12-08 Thread Greg Ewing
Phillip J. Eby wrote: > Lazy importing is putting a module object into sys.modules, but not > loading its contents until you attempt to get or set a module attribute. How is that expected to be useful? If you're not going to access any attributes of a module, why can you simply not import it in

Re: [Python-3000] Interest in PEP for callbacks on module import

2007-12-08 Thread Phillip J. Eby
At 10:49 PM 12/8/2007 +0100, Christian Heimes wrote: >Phillip J. Eby wrote: > > Note that in my implementation, an entry is added to sys.modules > > immediately, so this scenario can't happen without *replacing* the > > sys.modules entry. > >I like to separate the implementation of the post import

Re: [Python-3000] Interest in PEP for callbacks on module import

2007-12-08 Thread Phillip J. Eby
At 10:32 PM 12/8/2007 +0100, Christian Heimes wrote: >The pre import hook can probably be implemented in pure Python with a >meta path hook as described in http://www.python.org/dev/peps/pep-0302/. >I see the pre import hook as a lightweight meta path hook with an easy >to use interface. Which mea

Re: [Python-3000] Interest in PEP for callbacks on module import

2007-12-08 Thread Christian Heimes
Phillip J. Eby wrote: > Note that in my implementation, an entry is added to sys.modules > immediately, so this scenario can't happen without *replacing* the > sys.modules entry. I like to separate the implementation of the post import hook from lazy modules. I think that the hook and lazy modul

Re: [Python-3000] Interest in PEP for callbacks on module import

2007-12-08 Thread Christian Heimes
Nick Coghlan wrote: > With the new abstract base classes in Py3k, I can see it being > worthwhile to have a standard mechanism to allow callbacks to be > registered for execution when particular modules are first imported. > > For example, to handle the commented out case above: > >@imp.imp

Re: [Python-3000] Interest in PEP for callbacks on module import

2007-12-08 Thread Phillip J. Eby
At 09:55 PM 12/8/2007 +0100, Christian Heimes wrote: >Nick Coghlan wrote: > > I'm far from convinced that a from-scratch rewrite (particularly in C) > > is a great idea myself - that's why I suggested a PEP to look at some of > > the issues. > >Yesterday I wrote down a quick survey of codes with so

Re: [Python-3000] Interest in PEP for callbacks on module import

2007-12-08 Thread Christian Heimes
Nick Coghlan wrote: > I'm far from convinced that a from-scratch rewrite (particularly in C) > is a great idea myself - that's why I suggested a PEP to look at some of > the issues. Yesterday I wrote down a quick survey of codes with some use cases. Then I compared my ideas with PJE's import too

Re: [Python-3000] Interest in PEP for callbacks on module import

2007-12-08 Thread Brett Cannon
On Dec 8, 2007 7:32 AM, Christian Heimes <[EMAIL PROTECTED]> wrote: > Phillip J. Eby wrote: > > Misc. notes for the PEP: there should be a way to determine the laziness > > of a module object without causing it to load. I also think you should > > be able to set a module's __loader__, __path__, an

Re: [Python-3000] Interest in PEP for callbacks on module import

2007-12-08 Thread Christian Heimes
Phillip J. Eby wrote: > Misc. notes for the PEP: there should be a way to determine the laziness > of a module object without causing it to load. I also think you should > be able to set a module's __loader__, __path__, and __file__, without > causing it to load. That way, you can create a lazy m

Re: [Python-3000] Interest in PEP for callbacks on module import

2007-12-08 Thread Phillip J. Eby
At 03:56 PM 12/8/2007 +1000, Nick Coghlan wrote: >Phillip J. Eby wrote: > >> > Does anyone else think this is an issue worth pursuing? > > > > A qualified yes: the Importing package took a long time to get correct > > under all the crazy little twists and turns of importing, including > > correctly

Re: [Python-3000] Interest in PEP for callbacks on module import

2007-12-07 Thread Nick Coghlan
Phillip J. Eby wrote: >> > Does anyone else think this is an issue worth pursuing? > > A qualified yes: the Importing package took a long time to get correct > under all the crazy little twists and turns of importing, including > correctly handling things like the link between packages and their

Re: [Python-3000] Interest in PEP for callbacks on module import

2007-12-07 Thread Phillip J. Eby
At 12:33 PM 12/7/2007 +0100, Christian Heimes wrote: >Nick Coghlan wrote: > > For example, to handle the commented out case above: > > > >@imp.imported('decimal') > >def register(decimal): > >Inexact.register(decimal.Decimal) > >I like the syntax assuming that imp.imported(name) exp

Re: [Python-3000] Interest in PEP for callbacks on module import

2007-12-07 Thread Christian Heimes
Nick Coghlan wrote: > For example, to handle the commented out case above: > >@imp.imported('decimal') >def register(decimal): >Inexact.register(decimal.Decimal) I like the syntax assuming that imp.imported(name) expects a method that accepts the module object as argument. > I th

[Python-3000] Interest in PEP for callbacks on module import

2007-12-07 Thread Nick Coghlan
guido.van.rossum wrote: > Modified: python/branches/py3k/Lib/numbers.py > == > --- python/branches/py3k/Lib/numbers.py (original) > +++ python/branches/py3k/Lib/numbers.py Thu Dec 6 18:45:33 2007 > @@ -43,6 +43