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

Non-delegate types should not be callable#1247

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:masterfromalxnull:patch-1
Oct 5, 2020
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
1 change: 1 addition & 0 deletionsAUTHORS.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -77,3 +77,4 @@
- ([@stonebig](https://github.com/stonebig))
- ([@testrunner123](https://github.com/testrunner123))
- ([@DanBarzilian](https://github.com/DanBarzilian))
- ([@alxnull](https://github.com/alxnull))
1 change: 1 addition & 0 deletionsCHANGELOG.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,6 +28,7 @@ details about the cause of the failure
- Fix `object[]` parameters taking precedence when should not in overload resolution
- Fixed a bug where all .NET class instances were considered Iterable
- Fix incorrect choice of method to invoke when using keyword arguments.
- Fix non-delegate types incorrectly appearing as callable.

## [2.5.0][] - 2020-06-14

Expand Down
31 changes: 0 additions & 31 deletionssrc/runtime/classobject.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -278,36 +278,5 @@ public static int mp_ass_subscript(IntPtr ob, IntPtr idx, IntPtr v)

return 0;
}


/// <summary>
/// This is a hack. Generally, no managed class is considered callable
/// from Python - with the exception of System.Delegate. It is useful
/// to be able to call a System.Delegate instance directly, especially
/// when working with multicast delegates.
/// </summary>
public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw)
{
//ManagedType self = GetManagedObject(ob);
IntPtr tp = Runtime.PyObject_TYPE(ob);
var cb = (ClassBase)GetManagedObject(tp);

if (cb.type != typeof(Delegate))
{
Exceptions.SetError(Exceptions.TypeError, "object is not callable");
return IntPtr.Zero;
}

var co = (CLRObject)GetManagedObject(ob);
var d = co.inst as Delegate;
BindingFlags flags = BindingFlags.Public |
BindingFlags.NonPublic |
BindingFlags.Instance |
BindingFlags.Static;

MethodInfo method = d.GetType().GetMethod("Invoke", flags);
var binder = new MethodBinder(method);
return binder.Invoke(ob, args, kw);
}
}
}
10 changes: 10 additions & 0 deletionssrc/tests/test_class.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -315,3 +315,13 @@ def test_method_inheritance():

assert base.IsBase() == True
assert derived.IsBase() == False


def test_callable():
"""Test that only delegate subtypes are callable"""

def foo():
pass

assert callable(System.String("foo")) == False
assert callable(System.Action(foo)) == True

[8]ページ先頭

©2009-2025 Movatter.jp