In module 1:
class Parent(object):
def my_method(self):
print 'Hello World'
class Child(Parent):
def __init__(self, name):
self.name = name
def my_method(self):
# Do something
super(Child, self).my_method()
# Do something more
import sys
sys.modules[__name__] = Child(__name__)
In module 2:
import module1
module1.my_method()
Loading module2 fails.
Result:
File "c:\archive2\stack\module2.py", line 3, in <module>
module1.my_method()
File "c:\archive2\stack\module1.py", line 12, in my_method
super(Child, self).my_method()
TypeError: super() argument 1 must be type, not None
Looks like the value of variables Child and Parent is None when module2 is executed.
A similar problem was asked in this question. Is there a generic solution for accessing method of parent class when child class is not available in global namespace?