Seg, 2005-12-12 às 22:38 -0600, [EMAIL PROTECTED] escreveu:
>     Jim> I don't understand this argument.  Any mutating method or property
>     Jim> invoked by foreign code changes an object's state.  
> 
> Sure, but the only place I need to look for direct changes to the object's
> state are in the object's own code.
> 
>     Jim> If you provide a property or a pair if accessors that just sets and
>     Jim> gets an attribute with a slightly different name, that affords no
>     Jim> more protection than if people were setting the attribute directly.
> 
> Sure it does.  Suppose I get an exception in my code because some bit of
> code somewhere broke my assumptions about the values an attribute could
> assume.  If that attribute is only set by the object's own code, I can more
> easily debug it (stick in a print or an assert in the places where the
> attribute changes, etc).  If some external bit of code does something like
> 
>     self.foo = Foo()
>     ...
>     self.foo.attr = None
> 
> then later in Foo's code I have something like
> 
>     self.attr.callme()
> 
> The first thing I need to do is figure out who stomped on self.attr.

  I have never done this, but in theory you could replace attr with a
property whose getter uses sys._getframe() to log each modification of
the attribute, thus easily find out who did "self.foo.attr = None".
Almost like gdb's 'watch' command.

  Regards.

-- 
Gustavo J. A. M. Carneiro
<[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
The universe is always one step beyond logic.

Attachment: signature.asc
Description: Esta é uma parte de mensagem assinada digitalmente

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to