You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Can not call inherited method on nested class, when another nested class inherits from it and defines an override. #1787
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 the InheritFromNested class, then the call to o.GetSignal will resolve the proper inherited virtual base method.
Activity