🌐 AI搜索 & 代理 主页
Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e8ea7a6
1776 Inherit Generic Virtual Method Bug: Unit Test
rmadsen-ks Apr 27, 2022
691f207
1776 Inherit Generic Virtual Method Bug: Fix
rmadsen-ks Apr 28, 2022
e27ad8c
1774-ClassWithoutnamespace
rmadsen-ks Apr 29, 2022
f1fa696
better support for multiple inheritance
rmadsen-ks May 3, 2022
6f0b354
Fixed issue with protected constructors and classes with no constructor
rmadsen-ks May 3, 2022
3963621
Added supporr for class/property/method attributes.
rmadsen-ks May 5, 2022
4e0d003
- Expanded the way attributes amy be added
rmadsen-ks May 5, 2022
ea598a2
added support for creating abstract classes using a __clr_abstract__ …
rmadsen-ks May 6, 2022
d6abbb2
Improved AttributeError when looking for a symbol that does not exist…
rmadsen-ks May 24, 2022
2a84675
Added test to detect an issue with object construction.
rmadsen-ks Jun 28, 2022
172c642
got rid of a few deprecation warnings that pollute GitHub code review
lostmsu Jun 30, 2022
32d15eb
docs: Fix a few typos
timgates42 Jul 16, 2022
9eaf35f
Added support for marking properties with python types.
rmadsen-ks Sep 2, 2022
9ed94f6
Fixed issue calling base-base class implementation of methods.
rmadsen-ks Sep 2, 2022
da146d9
Merged with Pythonnet 3.0 RC.6.
rmadsen-ks Oct 28, 2022
b280b1b
Fixed bug related to converting number to a string
rmadsen-ks Oct 28, 2022
61c5d99
Added support for Python 3.11.
rmadsen-ks Oct 28, 2022
ed89819
Merge remote-tracking branch 'github/master'
rmadsen-ks Nov 14, 2023
56c8a39
Merge branch 'master' of github.com:pythonnet/pythonnet
rmadsen-ks Nov 14, 2023
e986114
Merge remote-tracking branch 'github/master'
rmadsen-ks Aug 1, 2024
be255ee
Merge branch 'master' into testbranch
filmor Dec 8, 2025
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
Next Next commit
Fixed issue calling base-base class implementation of methods.
  • Loading branch information
rmadsen-ks committed Oct 26, 2022
commit 9ed94f6cedef014918d8bdf7886f57cb15d2002b
1 change: 1 addition & 0 deletions src/python_tests_runner/PythonTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ static IEnumerable<string[]> PythonTestCases()
yield return new[] { "test_subclass", "test_class_with_attributes" };
yield return new[] { "test_subclass", "test_class_with_advanced_attribute" };
yield return new[] { "test_subclass", "test_more_subclasses" };
yield return new[] { "test_subclass", "test_more_subclasses2" };
yield return new[] { "test_subclass", "abstract_test" };
}

Expand Down
33 changes: 18 additions & 15 deletions src/runtime/Types/ClassDerived.cs
Original file line number Diff line number Diff line change
Expand Up @@ -522,23 +522,26 @@ private static void AddVirtualMethod(MethodInfo method, Type baseType, TypeBuild
string? baseMethodName = null;
if (!method.IsAbstract)
{
baseMethodName = "_" + baseType.Name + "__" + method.Name;
MethodBuilder baseMethodBuilder = typeBuilder.DefineMethod(baseMethodName,
MethodAttributes.Public |
MethodAttributes.Final |
MethodAttributes.HideBySig,
method.ReturnType,
parameterTypes);

// emit the assembly for calling the original method using call instead of callvirt
ILGenerator baseIl = baseMethodBuilder.GetILGenerator();
baseIl.Emit(OpCodes.Ldarg_0);
for (var i = 0; i < parameters.Length; ++i)
baseMethodName = "_" + method.DeclaringType.Name + "__" + method.Name;
if (baseType.GetMethod(baseMethodName) == null)
{
baseIl.Emit(OpCodes.Ldarg, i + 1);
MethodBuilder baseMethodBuilder = typeBuilder.DefineMethod(baseMethodName,
MethodAttributes.Public |
MethodAttributes.Final |
MethodAttributes.HideBySig,
method.ReturnType,
parameterTypes);

// emit the assembly for calling the original method using call instead of callvirt
ILGenerator baseIl = baseMethodBuilder.GetILGenerator();
baseIl.Emit(OpCodes.Ldarg_0);
for (var i = 0; i < parameters.Length; ++i)
{
baseIl.Emit(OpCodes.Ldarg, i + 1);
}
baseIl.Emit(OpCodes.Call, method);
baseIl.Emit(OpCodes.Ret);
}
baseIl.Emit(OpCodes.Call, method);
baseIl.Emit(OpCodes.Ret);
}

// override the original method with a new one that dispatches to python
Expand Down
18 changes: 14 additions & 4 deletions src/testing/subclasstest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,29 @@ public TestAttributeAttribute(int x, int y, string z = "x")
}
}

public abstract class SimpleClassBase
{
private int counter;
public virtual int IncrementThing()
{
return counter++;
}

public class SimpleClass
}

public abstract class SimpleClass : SimpleClassBase
{
public bool Initialized;

public SimpleClass()
{
Initialized = true;
}
private int counter = 0;
public virtual int IncrementThing()

public int CallIncrementThing()
{
return ++counter;
var x = IncrementThing();
return x;
}

public static void TestObject(object obj)
Expand Down
24 changes: 24 additions & 0 deletions tests/test_subclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ def __init__(self):
SimpleClass.Pause();
super().__init__()
def IncrementThing(self):
super().IncrementThing()
return 6;
SimpleClass.TestOnType(SubClass0)
SimpleClass.TestOnType(SubClass1)
Expand Down Expand Up @@ -465,3 +466,26 @@ class Derived(BaseClass):

import gc
gc.collect()
def test_more_subclasses2():
import clr
class SubClass50(SimpleClass):
def __init__(self):
super().__init__()
def IncrementThing(self):
return super().IncrementThing()

@clr.attribute(DebuggerDisplay("X"))

class SubClass51(SubClass50):
__namespace__ = "TestModule"
def __init__(self):
super().__init__()

def IncrementThing(self):
return super().IncrementThing() + 10
x = SubClass51()
print(x.CallIncrementThing())
print(x.CallIncrementThing())
print(x.CallIncrementThing())