Re: Overriding __setattr__ of a module - possible?

2010-06-19 Thread Fuzzyman
On Jun 18, 5:25 am, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Thu, 17 Jun 2010 07:12:23 -0300, Fuzzyman fuzzy...@gmail.com escribi�: On Jun 17, 10:29 am, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Thu, 17 Jun 2010 04:52:48 -0300, Alf P. Steinbach al...@start.no  

Re: Overriding __setattr__ of a module - possible?

2010-06-17 Thread Gabriel Genellina
En Wed, 16 Jun 2010 19:56:39 -0300, Ian Kelly ian.g.ke...@gmail.com escribió: On Wed, Jun 16, 2010 at 3:38 PM, John Nagle na...@animats.com wrote: That just leaves things in a state where even sys and import are undefined. Say what? It works fine for me. import proxy_mod proxy_mod.f()

Re: Overriding __setattr__ of a module - possible?

2010-06-17 Thread Alf P. Steinbach
* Gabriel Genellina, on 17.06.2010 09:25: En Wed, 16 Jun 2010 19:56:39 -0300, Ian Kelly ian.g.ke...@gmail.com escribió: On Wed, Jun 16, 2010 at 3:38 PM, John Nagle na...@animats.com wrote: That just leaves things in a state where even sys and import are undefined. Say what? It works fine

Re: Overriding __setattr__ of a module - possible?

2010-06-17 Thread Gabriel Genellina
En Thu, 17 Jun 2010 04:52:48 -0300, Alf P. Steinbach al...@start.no escribió: * Gabriel Genellina, on 17.06.2010 09:25: En Wed, 16 Jun 2010 19:56:39 -0300, Ian Kelly ian.g.ke...@gmail.com escribió: On Wed, Jun 16, 2010 at 3:38 PM, John Nagle na...@animats.com wrote: That just leaves

Re: Overriding __setattr__ of a module - possible?

2010-06-17 Thread Fuzzyman
On Jun 17, 10:29 am, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Thu, 17 Jun 2010 04:52:48 -0300, Alf P. Steinbach al...@start.no   escribió: But who would have thunk that Python *isn't dynamic enough*? :-) Yep... There are other examples too (e.g. the print statement in 2.x  

Re: Overriding __setattr__ of a module - possible?

2010-06-17 Thread John Nagle
On 6/17/2010 12:25 AM, Gabriel Genellina wrote: Note the fake.g(8) call: __setattr__ wasn't called. If the OP wants to trace assignments to global variables, this becomes a problem. A function defined in a module holds a reference to the module's __dict__ in its func_globals attribute. Getting

Re: Overriding __setattr__ of a module - possible?

2010-06-17 Thread Gabriel Genellina
En Thu, 17 Jun 2010 07:12:23 -0300, Fuzzyman fuzzy...@gmail.com escribió: On Jun 17, 10:29 am, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Thu, 17 Jun 2010 04:52:48 -0300, Alf P. Steinbach al...@start.no escribió: But who would have thunk that Python *isn't dynamic enough*? :-)

Re: Overriding __setattr__ of a module - possible?

2010-06-17 Thread Gabriel Genellina
En Thu, 17 Jun 2010 14:09:38 -0300, John Nagle na...@animats.com escribió: I'm trying out a proof of concept implementation for a new approach to safe threading. It's somewhat similar in concept to Alan Olsen's scheme. The basic difference is that once the program goes multi-thread, code

Re: Overriding __setattr__ of a module - possible?

2010-06-16 Thread Michele Simionato
On Jun 16, 7:25 am, John Nagle na...@animats.com wrote:     OK, working on this.  I can make a module make itself into a fake class, but can't yet do it to other modules from outside.                                         John Nagle I think you can with something like import module

Re: Overriding __setattr__ of a module - possible?

2010-06-16 Thread Christian Heimes
There aren't any; modules do not follow the class object protocol. They are simple types with a __dict__ (which you can't change, either, so no replacing it with a dict that implements __setattr__). You are wrong, my friend. :) Modules follow the new style class and instance protocol. Modules

Re: Overriding __setattr__ of a module - possible?

2010-06-16 Thread Lie Ryan
On 06/16/10 12:43, John Nagle wrote: Is it possible to override __setattr__ of a module? I want to capture changes to global variables for debug purposes. None of the following seem to have any effect. modu.__setattr__ = myfn setattr(modu, __setattr__, myfn)

Re: Overriding __setattr__ of a module - possible?

2010-06-16 Thread Steven D'Aprano
On Tue, 15 Jun 2010 20:34:47 -0700, Michele Simionato wrote: On Jun 16, 4:43 am, John Nagle na...@animats.com wrote:    Is it possible to override __setattr__ of a module?  I want to capture changes to global variables for debug purposes. [...] There is a dirty trick which involves fiddling

Re: Overriding __setattr__ of a module - possible?

2010-06-16 Thread Stephen Hansen
On 6/16/10 1:23 AM, Christian Heimes wrote: There aren't any; modules do not follow the class object protocol. They are simple types with a __dict__ (which you can't change, either, so no replacing it with a dict that implements __setattr__). You are wrong, my friend. :) Modules follow

Re: Overriding __setattr__ of a module - possible?

2010-06-16 Thread John Nagle
On 6/15/2010 8:34 PM, Michele Simionato wrote: On Jun 16, 4:43 am, John Naglena...@animats.com wrote: Is it possible to override __setattr__ of a module? I want to capture changes to global variables for debug purposes. None of the following seem to have any effect.

Re: Overriding __setattr__ of a module - possible?

2010-06-16 Thread Ian Kelly
On Wed, Jun 16, 2010 at 12:55 PM, John Nagle na...@animats.com wrote: Note that there are now two copies of a, one bound to the module and referenced in f, and a second bound to the class, and referenced by x.a.  Uh oh. The problem here is that when def f... was defined, its reference to a

Re: Overriding __setattr__ of a module - possible?

2010-06-16 Thread John Nagle
On 6/16/2010 1:10 PM, Ian Kelly wrote: On Wed, Jun 16, 2010 at 12:55 PM, John Naglena...@animats.com wrote: Note that there are now two copies of a, one bound to the module and referenced in f, and a second bound to the class, and referenced by x.a. Uh oh. The problem here is that when def

Re: Overriding __setattr__ of a module - possible?

2010-06-16 Thread Ian Kelly
On Wed, Jun 16, 2010 at 3:38 PM, John Nagle na...@animats.com wrote: That just leaves things in a state where even sys and import are undefined. Say what? It works fine for me. import proxy_mod proxy_mod.f() 1 proxy_mod.a = 2 setting a=2 proxy_mod.f() 2 proxy_mod.sys module 'sys'

Overriding __setattr__ of a module - possible?

2010-06-15 Thread John Nagle
Is it possible to override __setattr__ of a module? I want to capture changes to global variables for debug purposes. None of the following seem to have any effect. modu.__setattr__ = myfn setattr(modu, __setattr__, myfn) delattr(modu, __setattr__)

Re: Overriding __setattr__ of a module - possible?

2010-06-15 Thread Michele Simionato
On Jun 16, 4:43 am, John Nagle na...@animats.com wrote:    Is it possible to override __setattr__ of a module?  I want to capture changes to global variables for debug purposes.    None of the following seem to have any effect.         modu.__setattr__ = myfn         setattr(modu,

Re: Overriding __setattr__ of a module - possible?

2010-06-15 Thread John Nagle
On 6/15/2010 8:34 PM, Michele Simionato wrote: On Jun 16, 4:43 am, John Naglena...@animats.com wrote: Is it possible to override __setattr__ of a module? I want to capture changes to global variables for debug purposes. None of the following seem to have any effect.

Re: Overriding __setattr__ of a module - possible?

2010-06-15 Thread Stephen Hansen
On 6/15/10 9:16 PM, John Nagle wrote: Cute, but it doesn't work in general. Faking a module as a class fails when you simply call x() within the module. Huh? Explain how it doesn't work? I've done it at least twice (shamefully do I admit this) and it works fine. Real life code.

Re: Overriding __setattr__ of a module - possible?

2010-06-15 Thread John Nagle
On 6/15/2010 9:33 PM, Stephen Hansen wrote: On 6/15/10 9:16 PM, John Nagle wrote: Cute, but it doesn't work in general. Faking a module as a class fails when you simply call x() within the module. Huh? Explain how it doesn't work? I've done it at least twice (shamefully do I admit

Re: Overriding __setattr__ of a module - possible?

2010-06-15 Thread Stephen Hansen
On 6/15/10 10:25 PM, John Nagle wrote: On 6/15/2010 9:33 PM, Stephen Hansen wrote: Replacing the module with a class in sys.modules is really the only way to fake the behavior. OK, working on this. I can make a module make itself into a fake class, but can't yet do it to other