Description
Environment
- Pythonnet version: 2.3 with Another shot at #495 #503 applied
- Python version: 3.4 64-bit
- Operating System: Ubuntu 14.04
Details
- Describe what you were trying to get done.
I am trying to use python child of .NET class in python grandchild.
- What commands did you run to trigger this issue? If you can provide a
Minimal, Complete, and Verifiable example
this will help us understand the issue.
Following pure python code
class A:
def __init__(self):
self.foo()
def foo(self): print('A.foo')
class B(A):
def foo(self): print('B.foo')
a = A()
b = B()
works like expected and prints:
A.foo
B.foo
Consider Python classes constructed with pythonnet:
import clr
import System.Windows.Forms as WinForms
class PythonGroupBox(WinForms.GroupBox):
def __init__(self):
print("PythonGroupBox.__init__")
self.MyInit()
def MyInit(self):
print("PythonGroupBox MyInit")
class PythonGroupBoxDerived(PythonGroupBox):
def MyInit(self):
print("PythonGroupBoxDerived MyInit")
grp1 = PythonGroupBox()
grp2 = PythonGroupBoxDerived()
works fine and prints:
PythonGroupBox.init
PythonGroupBox MyInit
PPythonGroupBox.init
PythonGroupBoxDerived MyInit
Now the same with "namespace":
import clr
import System.Windows.Forms as WinForms
class PythonGroupBox(WinForms.GroupBox):
__namespace__ = "System.Windows.Forms"
def __init__(self):
print("PythonGroupBox.__init__")
self.MyInit()
def MyInit(self):
print("PythonGroupBox MyInit")
class PythonGroupBoxDerived(PythonGroupBox):
def MyInit(self):
print("PythonGroupBoxDerived MyInit")
grp1 = PythonGroupBox()
grp2 = PythonGroupBoxDerived()
The output is:
PythonGroupBox.init
PythonGroupBox MyInit
PythonGroupBox.init
PythonGroupBox MyInit
Error (1), because MyInit Method didn't get overloaded !!!
One more try:
import clr
import System.Windows.Forms as WinForms
class PythonGroupBox(WinForms.GroupBox):
__namespace__ = "System.Windows.Forms"
def __init__(self):
print("PythonGroupBox.__init__")
self.MyInit()
def MyInit(self):
print("PythonGroupBox MyInit")
class PythonGroupBoxDerived(PythonGroupBox):
__namespace__ = "System.Windows.Forms"
def MyInit(self):
print("PythonGroupBoxDerived MyInit")
grp1 = PythonGroupBox()
grp2 = PythonGroupBoxDerived()
Output gets really weird:
PythonGroupBox.init
PythonGroupBox MyInit
Error (2): during construction of PythonGroupBoxDerived the init() method was not called at all !!!
Important: this issue has nothing to do with issue #503: if I undo that fix than constructors get called twice, but errors described here persist.