--- a PPN by Garber Painting Akron. With Image Size Reduction included!URL: http://github.com/pythonnet/pythonnet/pull/2628.patch
s DualSubClass2(DualSubClass1):
+ __namespace__ = "Test"
+ class DualSubClass3(DualSubClass2):
+ __namespace__ = "Test"
+ def SayHello(self):
+ return super().SayHello() + " hi3"
+ def SayGoodbye(self):
+ return super().SayGoodbye() + "!"
+ obj = DualSubClass3()
+ helloResult = obj.SayHello()
+ goodByeResult = obj.SayGoodbye()
+ assert goodByeResult =="bye!!"
+ assert helloResult == "hello hi1 hi3"
From 23df0e8d9ff498b0b0e4d3e5cc98d7a72387debe Mon Sep 17 00:00:00 2001
From: romadsen-ks
Date: Thu, 9 Oct 2025 16:02:48 +0200
Subject: [PATCH 2/3] Added fix for calling virtual method on baseclass which
is not defined.
---
src/runtime/Types/ClassDerived.cs | 2 +-
src/testing/classtest.cs | 5 +++++
tests/test_subclass.py | 4 ++--
3 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/src/runtime/Types/ClassDerived.cs b/src/runtime/Types/ClassDerived.cs
index 0789fbb99..e03252e00 100644
--- a/src/runtime/Types/ClassDerived.cs
+++ b/src/runtime/Types/ClassDerived.cs
@@ -396,7 +396,7 @@ private static void AddVirtualMethod(MethodInfo method, Type baseType, TypeBuild
string? baseMethodName = null;
if (!method.IsAbstract)
{
- baseMethodName = "_" + baseType.Name + "__" + method.Name;
+ baseMethodName = "_" + method.DeclaringType.Name + "__" + method.Name;
MethodBuilder baseMethodBuilder = typeBuilder.DefineMethod(baseMethodName,
MethodAttributes.Public |
MethodAttributes.Final |
diff --git a/src/testing/classtest.cs b/src/testing/classtest.cs
index d7ca833cc..e7c224518 100644
--- a/src/testing/classtest.cs
+++ b/src/testing/classtest.cs
@@ -76,4 +76,9 @@ public virtual string SayGoodbye()
return "!";
}
}
+
+ public class SimpleClass2 : SimpleClass
+ {
+ // this class does not override SayGoodbye.
+ }
}
diff --git a/tests/test_subclass.py b/tests/test_subclass.py
index 5070006c4..57d6df2b4 100644
--- a/tests/test_subclass.py
+++ b/tests/test_subclass.py
@@ -9,7 +9,7 @@
import System
import pytest
from Python.Test import (IInterfaceTest, SubClassTest, EventArgsTest,
- FunctionsTest, IGenericInterface, GenericVirtualMethodTest, SimpleClass, ISayHello1)
+ FunctionsTest, IGenericInterface, GenericVirtualMethodTest, SimpleClass, SimpleClass2, ISayHello1)
from System.Collections.Generic import List
@@ -355,7 +355,7 @@ def test_multi_level_subclass():
exception if a method was not implemented in the middle of the tree.
"""
import clr
- class DualSubClass0(ISayHello1, SimpleClass):
+ class DualSubClass0(ISayHello1, SimpleClass2):
__namespace__ = "Test"
def SayHello(self):
return "hello"
From 9831bb91632d8e762eb8181b8678686271e6b213 Mon Sep 17 00:00:00 2001
From: Rolf Madsen
Date: Tue, 14 Oct 2025 10:31:31 +0200
Subject: [PATCH 3/3] minor cleanup
---
src/runtime/Types/ClassDerived.cs | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/src/runtime/Types/ClassDerived.cs b/src/runtime/Types/ClassDerived.cs
index e03252e00..75c596fac 100644
--- a/src/runtime/Types/ClassDerived.cs
+++ b/src/runtime/Types/ClassDerived.cs
@@ -253,7 +253,7 @@ internal static Type CreateDerivedType(string name,
// override the virtual method to call out to the python method, if there is one.
- AddVirtualMethod(method, baseType, typeBuilder, isDeclared);
+ AddVirtualMethod(method, typeBuilder);
}
// Add any additional methods and properties explicitly exposed from Python.
@@ -384,10 +384,8 @@ private static void AddConstructor(ConstructorInfo ctor, Type baseType, TypeBuil
//github.com/ and calls it, otherwise fall back to the base class method.
//github.com/
//github.com/ virtual method to be overridden
- //github.com/ Python callable object
//github.com/ TypeBuilder for the new type the method is to be added to
- //github.com/
- private static void AddVirtualMethod(MethodInfo method, Type baseType, TypeBuilder typeBuilder, bool isDeclared)
+ private static void AddVirtualMethod(MethodInfo method, TypeBuilder typeBuilder)
{
ParameterInfo[] parameters = method.GetParameters();
Type[] parameterTypes = (from param in parameters select param.ParameterType).ToArray();
pFad - Phonifier reborn
Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy