[Python-Dev] Changing existing class instances

Greg Stein gstein@lyra.org
Fri, 21 Jan 2000 03:12:57 -0800 (PST)


On Thu, 20 Jan 2000, Guido van Rossum wrote:
> Tim Peters:
>...
> > At the time my.py defines Misc, does Misc count as a class we're "about to
> > stomp on"?  If so-- & I've assumed so --it would wreak havoc.
> > 
> > But if not, I don't see how this case can be reliably distinguished "by
> > magic" from the cases where update is desired (if people are doing dynamic
> > updates to a long-running program, a new version of a class can come from
> > anywhere, so nothing like original file name or line number can distinguish
> > correctly either).
> 
> Fortunately, there's magic available: recently, all classes have a
> __module__ attribute that is set to the full name of the module that
> defined it (its key in __sys__.modules).
> 
> For functions, we would have to invent something similar.

func.func_globals


__module__ and func_globals can prevent *other* modules from redefining
something accidentally, but it doesn't prevent Badness from within the
module.
[ Tim just posted an example of this: his "def adder()" example... ]

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/