Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Can not call inherited method on nested class, when another nested class inherits from it and defines an override. #1787

Open
@Algoryx-NilsHjelte

Description

@Algoryx-NilsHjelte

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp