FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Inheritance not working with non-abstract base methods · Issue #755 · pythonnet/pythonnet · GitHub

Repository navigation

Inheritance not working with non-abstract base methods #755

Closed

Description

Environment

  • Pythonnet version: 2.3.0
  • Python version: 3.6.3
  • Operating System: Windows 10

Details

  • Describe what you were trying to get done.

This issue comes from this StackOverflow question.
I was trying to use a C# DLL which has a class that overrides a non-abstract method of its parent class. Although the new method should be used, pythonnet still calls the parent method. The code for a minimal DLL to reproduce this problem looks like this:

using System;

namespace InheritanceTest
{
    public class BaseClass
    {
        public bool Transmit()
        {
            throw new NotImplementedException();
        }
    }

    public class InheritedClass: BaseClass
    {
        public new bool Transmit()
        {
            Console.WriteLine("Success!");
            return true;
        }
    }
}

In the following python code, BaseClass.Transmit should be called when BaseClass is directly instantiated and InheritedClass.Transmit when InheritedClass is instantiated. However, BaseClass.Transmit is called both times.

## setup
import clr
import os

clr.AddReference(os.getcwd() + '\\InheritanceTest.dll')
import InheritanceTest

## method test

base_class = InheritanceTest.BaseClass()
base_class.Transmit() # throws a NotImplementedException as expected

inherited_class = InheritanceTest.InheritedClass()
inherited_class.Transmit() # still throws a NotImplementedException, although it should call InheritedClass.Transmit

Activity

  1. den-run-ai commented on Oct 21, 2018

    Contributor
  2. bminixhofer commented on Oct 23, 2018

    Author

    @denfromufa It seems to me that #552 is the exact same issue (although worded a little strangely in my opinion, i wasn't able to find it when first researching the problem).
    #756 fixes #552 too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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


      Back | FazBrowse Home | New Git URL