The goal was to implement some kind of plugin frame diagram, where plugins are subclasses (i.e. B) of the same base class (i.e. A). The base class is loaded with standard imports, while subclasses are loaded with imp.load_module () from the path of a known package (i.e. Pkg).
pkg/ __init__.py mod1.py class A mod2.py class B(pkg.mod1.A)
This worked fine with real subclasses, i.e.
# test_1.py import pkg from pkg import mod1 import imp tup = imp.find_module('mod2', pkg.__path__) mod2 = imp.load_module('mod2', tup[0], tup[1], tup[2]) print(issubclass(mod2.B, mod1.A))
But the problem arose while testing the base class itself,
# test_2.py import pkg from pkg import mod1 import imp tup = imp.find_module('mod1', pkg.__path__) mod0 = imp.load_module('mod1', tup[0], tup[1], tup[2]) print(issubclass(mod0.A, mod1.A))
But mod0.A and mod1.A are actually the same class from the same file (pkg / mod1.py).
This problem occurs in both python 2.7 and 3.2.
Now the question is twofold: a) Is this the expected function or error issubclass () and b) How to get rid of this without changing the contents of pkg?
liuyu source share