- Notifications
You must be signed in to change notification settings - Fork749
Open
Description
Environment
- Python.NET version: 3.0.5
- Tested on two configurations:
- Windows 10, Python 3.12.4, .NET Framework
- Windows 10, Python 3.12.4, .NET 9.0.201
Details
Code to reproduce the issue is below.
.NET library code:
namespaceTestLib{publicclassBaseClass{publicvirtualstringFoo(){return"Foo";}publicvirtualstringBar(){return"Bar";}}publicclassDerivedClass:BaseClass{publicoverridestringFoo(){return"DerivedFoo";}}}
Python code:
frompathlibimportPathimportclrclr.AddReference(str(Path(__file__).parent/'TestLib.dll'))fromTestLibimportBaseClass,DerivedClassclassTestClass(DerivedClass):__namespace__='CrlTest'defFoo(self):return'Test'+super().Foo()defBar(self):# This work fine# return 'Test' + DerivedClass.Bar(self)# This calls TestClass::Bar for some reasonreturn'Test'+super().Bar()if__name__=='__main__':stc=TestClass()print('Foo() -> '+stc.Foo())print('Bar() -> '+stc.Bar())
Python script output:
Foo() -> TestDerivedFooProcess is terminated due to StackOverflowException.
For some reason callingsuper().Bar()
results in callingTestClass.Bar(self)
instead ofDerivedClass.Bar(self)
, which in the end results in infinite recursion. CallingDerivedClass.Bar(self)
directly works as expected.
It seem to be related to the fact that the method you try to override in Python is not defined in the immediate parent class, sinceFoo
in the example works fine.
Metadata
Metadata
Assignees
Labels
No labels