8000 Select correct method to invoke when keyword arguments are used by danabr · Pull Request #1242 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content

Select correct method to invoke when keyword arguments are used #1242

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all 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 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ details about the cause of the failure
- Fix incorrect dereference in params array handling
- 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.

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

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/constructorbinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ internal object InvokeRaw(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info)
// any extra args are intended for the subclass' __init__.

IntPtr eargs = Runtime.PyTuple_New(0);
binding = Bind(inst, eargs, kw);
binding = Bind(inst, eargs, IntPtr.Zero);
Runtime.XDecref(eargs);

if (binding == null)
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/methodbinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ static bool MatchesArgumentCount(int positionalArgumentCount, ParameterInfo[] pa
var match = false;
paramsArray = parameters.Length > 0 ? Attribute.IsDefined(parameters[parameters.Length - 1], typeof(ParamArrayAttribute)) : false;

if (positionalArgumentCount == parameters.Length)
if (positionalArgumentCount == parameters.Length && kwargDict.Count == 0)
{
match = true;
}
Expand Down
6 changes: 6 additions & 0 deletions src/testing/methodtest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,12 @@ public string PublicMethod(string echo)
return echo;
}
}

public class MethodArityTest
{
public string Foo(int a) { return "Arity 1"; }
public string Foo(int a, int b) { return "Arity 2"; }
}
}

namespace PlainOldNamespace
Expand Down
7 changes: 7 additions & 0 deletions src/tests/test_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -1149,3 +1149,10 @@ def test_optional_and_default_params():

res = MethodTest.OptionalAndDefaultParams2(b=2, c=3)
assert res == "0232"

def test_keyword_arg_method_resolution():
from Python.Test import MethodArityTest

ob = MethodArityTest()
assert ob.Foo(1, b=2) == "Arity 2"

0