8000 Inheritance not working with non-abstract base methods by smourier · Pull Request #756 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content

Inheritance not working with non-abstract base methods #756

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 29, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add unit test
  • Loading branch information
filmor committed Oct 29, 2018
commit 2fff2481bc377bd38cd850f16be7fbb9c4a0930d
14 changes: 14 additions & 0 deletions src/testing/InheritanceTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace Python.Test
{
public class BaseClass
{
public bool IsBase() => true;
}

public class DerivedClass : BaseClass
{
public new bool IsBase() => false;
}
}
5 changes: 3 additions & 2 deletions src/testing/Python.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -83,6 +83,7 @@
<Compile Include="generictest.cs" />
<Compile Include="globaltest.cs" />
<Compile Include="indexertest.cs" />
<Compile Include="InheritanceTest.cs" />
<Compile Include="interfacetest.cs" />
<Compile Include="methodtest.cs" />
<Compile Include="moduletest.cs" />
Expand Down Expand Up @@ -110,4 +111,4 @@
<Copy SourceFiles="$(TargetAssembly)" DestinationFolder="$(SolutionDir)\src\tests\fixtures" />
<!--Copy SourceFiles="$(TargetAssemblyPdb)" Condition="Exists('$(TargetAssemblyPdb)')" DestinationFolder="$(PythonBuildDir)" /-->
</Target>
</Project>
</Project>
11 changes: 11 additions & 0 deletions src/tests/test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,14 @@ def PyCallback(self, self2):
testobj.DoCallback()
assert testobj.PyCallbackWasCalled
assert testobj.SameReference


def test_method_inheritance():
"""Ensure that we call the overridden method instead of the one provided in
the base class."""

base = Test.BaseClass()
derived = Test.DerivedClass()

assert base.IsBase() == True
assert derived.IsBase() == False
0