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

Allow Python to overwrite .NET methods#1545

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

Merged
lostmsu merged 1 commit intopythonnet:masterfromlosttech:allow-method-overwrite
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
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
12 changes: 0 additions & 12 deletionssrc/runtime/extensiontype.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -87,18 +87,6 @@ public static int tp_setattro(IntPtr ob, IntPtr key, IntPtr val)
return -1;
}


/// <summary>
/// Default __set__ implementation - this prevents descriptor instances
/// being silently replaced in a type __dict__ by default __setattr__.
/// </summary>
public static int tp_descr_set(IntPtr ds, IntPtr ob, IntPtr val)
{
Exceptions.SetError(Exceptions.AttributeError, "attribute is read-only");
return -1;
}


public static void tp_dealloc(IntPtr ob)
{
// Clean up a Python instance of this extension type. This
Expand Down
2 changes: 2 additions & 0 deletionssrc/testing/methodtest.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,6 +14,8 @@ public MethodTest()
{
}

public string OverwritableMethod() => "overwritable";

public string PublicMethod()
{
return "public";
Expand Down
35 changes: 5 additions & 30 deletionstests/test_method.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,37 +6,12 @@
import pytest
from Python.Test import MethodTest

def test_instance_method_overwritable():
"""Test instance method overwriting."""

def test_instance_method_descriptor():
"""Test instance method descriptor behavior."""

with pytest.raises(AttributeError):
MethodTest().PublicMethod = 0

with pytest.raises(AttributeError):
MethodTest.PublicMethod = 0

with pytest.raises(AttributeError):
del MethodTest().PublicMethod

with pytest.raises(AttributeError):
del MethodTest.PublicMethod


def test_static_method_descriptor():
"""Test static method descriptor behavior."""

with pytest.raises(AttributeError):
MethodTest().PublicStaticMethod = 0

with pytest.raises(AttributeError):
MethodTest.PublicStaticMethod = 0

with pytest.raises(AttributeError):
del MethodTest().PublicStaticMethod

with pytest.raises(AttributeError):
del MethodTest.PublicStaticMethod
ob = MethodTest()
ob.OverwritableMethod = lambda: "overwritten"
assert ob.OverwritableMethod() == "overwritten"


def test_public_instance_method():
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp