Skip to content

Commit 0dc9fa5

Browse files
committed
allow Python to overwrite .NET methods
1 parent 5dff25f commit 0dc9fa5

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

src/embed_tests/CallableObject.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ public void CallMethodCanBeInheritedFromPython() {
3838
}
3939
}
4040

41+
[Test]
42+
public void CanOverwriteCall() {
43+
var callViaInheritance = new CallViaInheritance();
44+
using var _ = Py.GIL();
45+
using var scope = Py.CreateScope();
46+
scope.Set("o", callViaInheritance);
47+
scope.Exec("orig_call = o.Call");
48+
scope.Exec("o.Call = lambda a: orig_call(a*7)");
49+
int result = scope.Eval<int>("o.Call(5)");
50+
Assert.AreEqual(105, result);
51+
}
52+
4153
class Doubler {
4254
public int __call__(int arg) => 2 * arg;
4355
}

src/runtime/extensiontype.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,6 @@ public static int tp_setattro(IntPtr ob, IntPtr key, IntPtr val)
7676
}
7777

7878

79-
/// <summary>
80-
/// Default __set__ implementation - this prevents descriptor instances
81-
/// being silently replaced in a type __dict__ by default __setattr__.
82-
/// </summary>
83-
public static int tp_descr_set(IntPtr ds, IntPtr ob, IntPtr val)
84-
{
85-
Exceptions.SetError(Exceptions.AttributeError, "attribute is read-only");
86-
return -1;
87-
}
88-
89-
9079
/// <summary>
9180
/// Default dealloc implementation.
9281
/// </summary>

0 commit comments

Comments
 (0)