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

Commit03cf4ac

Browse files
authored
Non-delegate types should not be callable (#1247)
Removed the ClassObject.tp_call method which seemed to be unused. Also added a test case.
1 parent50d947f commit03cf4ac

File tree

4 files changed

+12
-31
lines changed

4 files changed

+12
-31
lines changed

‎AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,4 @@
7777
- ([@stonebig](https://github.com/stonebig))
7878
- ([@testrunner123](https://github.com/testrunner123))
7979
- ([@DanBarzilian](https://github.com/DanBarzilian))
80+
- ([@alxnull](https://github.com/alxnull))

‎CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ details about the cause of the failure
2828
- Fix`object[]` parameters taking precedence when should not in overload resolution
2929
- Fixed a bug where all .NET class instances were considered Iterable
3030
- Fix incorrect choice of method to invoke when using keyword arguments.
31+
- Fix non-delegate types incorrectly appearing as callable.
3132

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

‎src/runtime/classobject.cs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -278,36 +278,5 @@ public static int mp_ass_subscript(IntPtr ob, IntPtr idx, IntPtr v)
278278

279279
return0;
280280
}
281-
282-
283-
/// <summary>
284-
/// This is a hack. Generally, no managed class is considered callable
285-
/// from Python - with the exception of System.Delegate. It is useful
286-
/// to be able to call a System.Delegate instance directly, especially
287-
/// when working with multicast delegates.
288-
/// </summary>
289-
publicstaticIntPtrtp_call(IntPtrob,IntPtrargs,IntPtrkw)
290-
{
291-
//ManagedType self = GetManagedObject(ob);
292-
IntPtrtp=Runtime.PyObject_TYPE(ob);
293-
varcb=(ClassBase)GetManagedObject(tp);
294-
295-
if(cb.type!=typeof(Delegate))
296-
{
297-
Exceptions.SetError(Exceptions.TypeError,"object is not callable");
298-
returnIntPtr.Zero;
299-
}
300-
301-
varco=(CLRObject)GetManagedObject(ob);
302-
vard=co.instasDelegate;
303-
BindingFlagsflags=BindingFlags.Public|
304-
BindingFlags.NonPublic|
305-
BindingFlags.Instance|
306-
BindingFlags.Static;
307-
308-
MethodInfomethod=d.GetType().GetMethod("Invoke",flags);
309-
varbinder=newMethodBinder(method);
310-
returnbinder.Invoke(ob,args,kw);
311-
}
312281
}
313282
}

‎src/tests/test_class.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,3 +315,13 @@ def test_method_inheritance():
315315

316316
assertbase.IsBase()==True
317317
assertderived.IsBase()==False
318+
319+
320+
deftest_callable():
321+
"""Test that only delegate subtypes are callable"""
322+
323+
deffoo():
324+
pass
325+
326+
assertcallable(System.String("foo"))==False
327+
assertcallable(System.Action(foo))==True

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp