Classes loading using script console cause isinstance to return False

We have upgraded from 8.1.10 to 8.1.17 and we are see a difference in the way the script console is loading files/classes.

Here is an example

image

image

It appears that the testClass.TestClass is getting loaded twice with two different ids. Once when the console starts and then again when I access the property on TestClass2 which references TestClass.

Any help on this would be great. This does not seem to be a problem when running the code in a client only a problem in the script console.

Any ideas on this? It would really be nice to use the console to do quick code tests rather than having to go over to the client. We are now on 8.1.18 and this problem still exists.

Bump.

I have a module in my project script library built around Python's unittest. For the time being, I intend to run the tests manually, for a semi-automated approach to testing.

The way the modules are loaded cause unittest.TestCase.assertIsInstance() to return False unexpectedly. I even validated that the assert is doing what you would think... see jython/jython/lib-python/2.7/unittest/case.py.

I've provided what I believe to be the smallest reproduceable test. It's not much different from what OP provided 18mo ago.

# --- moduleA -----------------------------------------------------------------
def run():
	
	print isinstance(tmp.moduleB.getClassC(), tmp.moduleC.C)
	# False ?
	
	print(isinstance(tmp.moduleC.C(), tmp.moduleC.C))
	# True
# --- moduleB -----------------------------------------------------------------
def getClassC():
	return tmp.moduleC.C()
# --- moduleC -----------------------------------------------------------------
class C(object):
	def __init__(self):
		self.c = "c"

This can be called from the script console by moduleA.run().

Bump again. I just spent the last three hours debugging various parts of my code to figure out what caused isinstance to fail, and yes, somehow the class is loaded twice with different IDs when used in the script console.

Rather annoying that this does not work as expected. Makes it very cumbersome to quickly test a piece of code in the script console.

1 Like

See this topic:

But also, the script console is wrapped internally to capture output, so runs its own script module initialization, separate from Vision.