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

Commit7604e39

Browse files
committed
allow Python to overwrite .NET methods
1 parentee0ab7f commit7604e39

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

‎src/embed_tests/CallableObject.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
usingNUnit.Framework;
2+
3+
usingPython.Runtime;
4+
5+
namespacePython.EmbeddingTest
6+
{
7+
classCallableObject
8+
{
9+
[OneTimeSetUp]
10+
publicvoidSetUp()
11+
{
12+
PythonEngine.Initialize();
13+
}
14+
15+
[OneTimeTearDown]
16+
publicvoidDispose()
17+
{
18+
PythonEngine.Shutdown();
19+
}
20+
21+
[Test]
22+
publicvoidPythonCanOverwriteMethods()
23+
{
24+
varobj=newPublicCallMethod();
25+
usingvar_=Py.GIL();
26+
usingvarscope=Py.CreateScope();
27+
scope.Set("o",obj);
28+
scope.Exec("orig_call = o.Call");
29+
scope.Exec("o.Call = lambda a: orig_call(a*7)");
30+
intresult=scope.Eval<int>("o.Call(5)");
31+
Assert.AreEqual(105,result);
32+
}
33+
34+
classPublicCallMethod
35+
{
36+
publicintCall(intarg)=>3*arg;
37+
}
38+
}
39+
}

‎src/runtime/extensiontype.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,6 @@ public static int tp_setattro(IntPtr ob, IntPtr key, IntPtr val)
8787
return-1;
8888
}
8989

90-
91-
/// <summary>
92-
/// Default __set__ implementation - this prevents descriptor instances
93-
/// being silently replaced in a type __dict__ by default __setattr__.
94-
/// </summary>
95-
publicstaticinttp_descr_set(IntPtrds,IntPtrob,IntPtrval)
96-
{
97-
Exceptions.SetError(Exceptions.AttributeError,"attribute is read-only");
98-
return-1;
99-
}
100-
101-
10290
publicstaticvoidtp_dealloc(IntPtrob)
10391
{
10492
// Clean up a Python instance of this extension type. This

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp