FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Method overload object type by vmuriart · Pull Request #377 · pythonnet/pythonnet · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cs  (2) .py  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion src/runtime/methodbinder.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
if (clrtype != null)
{
var typematch = false;
if (pi[n].ParameterType != clrtype)
if ((pi[n].ParameterType != typeof(object)) && (pi[n].ParameterType != clrtype))
{
IntPtr pytype = Converter.GetPythonTypeByAlias(pi[n].ParameterType);
pyoptype = Runtime.PyObject_Type(op);
Expand Down
65 changes: 65 additions & 0 deletions src/testing/methodtest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,71 @@ public static int[] TestOverloadedParams(int v, int[] args)
return args;
}

public static string TestOverloadedNoObject(int i)
{
return "Got int";
}

public static string TestOverloadedObject(int i)
{
return "Got int";
}

public static string TestOverloadedObject(object o)
{
return "Got object";
}

public static string TestOverloadedObjectTwo(int a, int b)
{
return "Got int-int";
}

public static string TestOverloadedObjectTwo(string a, string b)
{
return "Got string-string";
}

public static string TestOverloadedObjectTwo(string a, int b)
{
return "Got string-int";
}

public static string TestOverloadedObjectTwo(string a, object b)
{
return "Got string-object";
}

public static string TestOverloadedObjectTwo(int a, object b)
{
return "Got int-object";
}

public static string TestOverloadedObjectTwo(object a, int b)
{
return "Got object-int";
}

public static string TestOverloadedObjectTwo(object a, object b)

den-run-ai Feb 21, 2017
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

you don't test this method in python

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

because you changed the test for it above. I re-added a test for it.

{
return "Got object-object";
}

public static string TestOverloadedObjectTwo(int a, string b)
{
return "Got int-string";
}

public static string TestOverloadedObjectThree(object a, int b)
{
return "Got object-int";
}

public static string TestOverloadedObjectThree(int a, object b)
{
return "Got int-object";
}

public static bool TestStringOutParams(string s, out string s1)
{
s1 = "output string";
Expand Down
50 changes: 50 additions & 0 deletions src/tests/test_method.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -769,3 +769,53 @@ def test_wrong_overload():
res = System.Math.Max(System.Double(50.5), 50.1)
assert res == 50.5
assert type(res) == float


def test_no_object_in_param():
"""Test that fix for #203 doesn't break behavior w/ no object overload"""

res = MethodTest.TestOverloadedNoObject(5)
assert res == "Got int"

with pytest.raises(TypeError):
MethodTest.TestOverloadedNoObject("test")


def test_object_in_param():
"""Test regression introduced by #151 in which Object method overloads
aren't being used. See #203 for issue."""

res = MethodTest.TestOverloadedObject(5)
assert res == "Got int"

res = MethodTest.TestOverloadedObject("test")
assert res == "Got object"


def test_object_in_multiparam():
"""Test method with object multiparams behaves"""

res = MethodTest.TestOverloadedObjectTwo(5, 5)
assert res == "Got int-int"

res = MethodTest.TestOverloadedObjectTwo(5, "foo")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

will this break if you add:

public static string TestOverloadedObjectTwo(int a, string b)
        {
            return "Got int-string";
        }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Now its there.

assert res == "Got int-string"

res = MethodTest.TestOverloadedObjectTwo("foo", 7.24)
assert res == "Got string-object"

res = MethodTest.TestOverloadedObjectTwo("foo", "bar")
assert res == "Got string-string"

res = MethodTest.TestOverloadedObjectTwo("foo", 5)
assert res == "Got string-int"

res = MethodTest.TestOverloadedObjectTwo(7.24, 7.24)
assert res == "Got object-object"


def test_object_in_multiparam_exception():
"""Test method with object multiparams behaves"""

with pytest.raises(TypeError):
MethodTest.TestOverloadedObjectThree("foo", "bar")

Back | FazBrowse Home | New Git URL