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

Object identity, Interfaces and Attributes#2019

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
15 commits
Select commitHold shift + click to select a range
ab531f8
1776 Inherit Generic Virtual Method Bug: Unit Test
rmadsen-ksApr 27, 2022
bfcf1d1
1776 Inherit Generic Virtual Method Bug: Fix
rmadsen-ksApr 28, 2022
eb4ce37
1774-ClassWithoutnamespace
rmadsen-ksApr 29, 2022
a2c80cd
better support for multiple inheritance
rmadsen-ksMay 3, 2022
65c2c00
Fixed issue with protected constructors and classes with no constructor
rmadsen-ksMay 3, 2022
28f4717
Added supporr for class/property/method attributes.
rmadsen-ksMay 5, 2022
014ef2e
- Expanded the way attributes amy be added
rmadsen-ksMay 5, 2022
2449bd2
added support for creating abstract classes using a __clr_abstract__ …
rmadsen-ksMay 6, 2022
7980fc4
Improved AttributeError when looking for a symbol that does not exist…
rmadsen-ksMay 24, 2022
cf2c27a
Added test to detect an issue with object construction.
rmadsen-ksJun 28, 2022
adc6613
Added support for marking properties with python types.
rmadsen-ksSep 2, 2022
9373a03
Fixed issue calling base-base class implementation of methods.
rmadsen-ksSep 2, 2022
ab12481
Merged with Pythonnet 3.0 RC.6.
rmadsen-ksOct 28, 2022
c290bf9
Merge branch 'master' of github.com:pythonnet/pythonnet into 1776-Inh…
rmadsen-ksNov 18, 2022
bb988cd
Cleanup and comments
rmadsen-ksNov 18, 2022
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
PrevPrevious commit
NextNext commit
Fixed issue calling base-base class implementation of methods.
  • Loading branch information
@rmadsen-ks
rmadsen-ks committedOct 31, 2022
commit9373a03a9938a68f8b447d2781b0ddf77daac83d
1 change: 1 addition & 0 deletionssrc/python_tests_runner/PythonTestRunner.cs
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionssrc/runtime/Types/ClassDerived.cs
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionssrc/testing/subclasstest.cs
View file
Open in desktop
Original file line numberDiff line numberDiff 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;
publicvirtualintIncrementThing()

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

public static void TestObject(object obj)
Expand Down
24 changes: 24 additions & 0 deletionstests/test_subclass.py
View file
Open in desktop
Original file line numberDiff line numberDiff 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 DownExpand 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())



[8]ページ先頭

©2009-2025 Movatter.jp