reloading modules and isinstance()

2007-12-04 Thread Tlis
I am using a software system with an embedded Python interpreter
(version 2.3) for scripting. The KcsPoint2D.py module contains a
Point2D class with the following method:

def SetFromMidpoint(self, p1, p2):
   if not isinstance(p1, Point2D) or not isinstance(p2, Point2D):
  raise TypeError, 'some error message'
   ---

The problem is that after I launch my script once, and then use the
'Reload modules' button (presumably it calls reload() on all loaded
modules), the isinstance() tests shown above fails, even though the
expressions:

type(self)
type(p1)
type(p2)

all show: class 'KcsPoint2D.Point2D'

Could you explain, please what is going on? Why the isinstance()
function returns False?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reloading modules and isinstance()

2007-12-05 Thread Tlis
On 5 Dec, 13:18, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Tue, 04 Dec 2007 15:41:48 +0100, Diez B. Roggisch wrote:
> > You just discovered one reason why reload() is a bad idea and IMHO
> > shouldn't be used at all - as tempting it might be.
>
> I disagree -- I find reload() extremely useful for interactively testing
> modules. But I would never dream of using it in production code!
>
> --
> Steven.

Please note, that I was using the 'Reload modules' functionality of
the software system in use, rather than the reload() function
directly. I admit, though, that in the background it just may call
reload() ...

With all the problems of the reload() function, I still hope, that
there should be possible to write a safe module 'reloader', that would
fix the references, as required (e.g. by changing the
variable.__class__ references). This should be provided by every
serious Python development environment.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reloading modules and isinstance()

2007-12-14 Thread Tlis
Hi,

I have found that it is possible to reassign the instance.__class__
reference to the same class (but after reloading) to make the
isinstance() test work again! I know that it is a kind of hacking of
the Python interpreter, but it works :-)
-- 
http://mail.python.org/mailman/listinfo/python-list