- Notifications
You must be signed in to change notification settings - Fork750
Open
Description
This is a very specific setup with classes and inheritance, but is exactly what happened to us and where pythonnet does not do the right thing.
It is closely related to#1420 but a slightly different configuration.
Here is code to reproduce the issue:
namespacepythonnet_testing{publicclassCreator{publicstaticobjectCreateObject()=>newBaseClass.NestedClass();}publicclassBaseClass{publicvirtualstringGetSignal()=>"hello";publicclassNestedClass:BaseClass{// NOTE: This is using the default `GetSignal` implementation}// NOTE: This class inherits from the nested class, and overrides the method in the base class// When this class is defined, we can no longer call `GetSignal` on instances of `NestedClass`// ==> `Unhandled exception. Python.Runtime.PythonException: 'NestedClass' object has no attribute 'GetSignal'`publicclassInheritFromNested:BaseClass.NestedClass{publicoverridestringGetSignal()=>"override";}}classProgram{staticvoidMain(string[]args){varpyCode=@"import pythonnet_testingo = pythonnet_testing.Creator.CreateObject()print(f'Method call: {o.GetSignal()}') ";Runtime.PythonDLL="libpython3.9.dylib";PythonEngine.Initialize();using(Py.GIL()){PythonEngine.Exec(pyCode);}PythonEngine.Shutdown();}}}
NOTE: If I remove theInheritFromNested
class, then the call too.GetSignal
will resolve the proper inherited virtual base method.
Metadata
Metadata
Assignees
Labels
No labels