-
Notifications
You must be signed in to change notification settings - Fork 712
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
Method overload object type #377
Conversation
@vmuriart what happens with multiple arguments, when overloaded methods have |
@denfromufa good question. No idea.
These 4 functions look enough to cover the possibilities or do I need more? |
we need one super-loaded method which covers all these cases from this meta-issue :) |
That sounds much broader than the scope of this |
@vmuriart I understand, your example looks good. My suggestion was not serious anyway. But we may hit issues when dealing with sub-classes and ambiguous cases in the overload. IMO, pythonnet should be very strict by default in method resolution. See examples how C# compiler had to break method overloading in .NET 4.0: |
@denfromufa No worries. My goal is to restore similar behavior to what |
@denfromufa Multiple arguments with objects works as expected. |
@vmuriart no failure cases in overloads to make sure that they fail. No strings in overloaded method arguments when creating the methods in c#, but then you use strings as arguments when invoking from python. |
17499ae
to
c9ab4ea
Compare
I think I understood your request correctly. I added a test to check for failure/exception. |
Can you add more overloaded methods such as:
```
public static string TestOverloadedObjectTwo(string a, string b){return
"Got string-string";}
```
Which one would the method resolution pick object or string? Does the order
of defined methods matter?
Wrong result would be much worse than flagging ambiguity or failure in
method resolution.
…On Wed, Feb 15, 2017, 1:26 AM Victor Uriarte ***@***.***> wrote:
I think I understood your request correctly. I added a test to check for
failure/exception.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#377 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHgZ5ZWYSupa6rOYtu-trQflb6-85xhrks5rcqiogaJpZM4MBRiU>
.
|
@denfromufa I think you are asking for these tests I added them on a separate commit. Earlier when I was working on this pull request I used those tests to make sure I wasn't reverting the behavior you are describing. On earlier implementations, I reverted the behavior so those tests kept me in check. The string-string check is analogous to the int-int check vs obj-obj check |
@vmuriart string check is not analogous, you are assuming that strings are object in your tests. In fact string is subclass of object. |
@denfromufa
Sources: |
yes, int is also object subclass. However you use int in C# overloaded methods, while not using strings. Let me give some examples. |
c9ab4ea
to
e4f90ab
Compare
@vmuriart here is what I suggested to add. I cannot test locally, due to #385 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)
{
return "Got object-object";
}
public static string TestOverloadedObjectThree(object a, int b)
{
return "Got object-int";
}
public static string TestOverloadedObjectThree(int a, object b)
{
return "Got int-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")
assert res == "Got int-object"
res = MethodTest.TestOverloadedObjectTwo("foo", 5)
assert res == "Got object-int"
res = MethodTest.TestOverloadedObjectTwo("foo", "bar")
assert res == "Got object-object"
res = MethodTest.TestOverloadedObjectTwo("foo", System.Object)
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"
|
e4f90ab
to
75fc3ec
Compare
@denfromufa Added your tests, but had to modify remove a couple of the conditions I had added earlier since the function signatures had changed. |
src/runtime/methodbinder.cs
Outdated
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add brackets around each logical?
@vmuriart I left 2 comments inline with the code |
I'll review on Tuesday. Though the parenthesis seem superfluous since it
isn't consistent throughout.
…On Fri, Feb 17, 2017 at 18:56 denfromufa ***@***.***> wrote:
@vmuriart <https://github.com/vmuriart> I left 2 comments inline with the
code
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#377 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AMr87EoUuLcuTE5k0mXi3kl9MNwyHCvPks5rdl3GgaJpZM4MBRiU>
.
|
yes, brackets is very minor. But I feel the same way as this person:
http://stackoverflow.com/a/23816736/2230844
On Fri, Feb 17, 2017 at 9:28 PM, Victor Uriarte <[email protected]>
wrote:
… I'll review on Tuesday. Though the parenthesis seem superfluous since it
isn't consistent throughout.
On Fri, Feb 17, 2017 at 18:56 denfromufa ***@***.***> wrote:
> @vmuriart <https://github.com/vmuriart> I left 2 comments inline with
the
> code
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#377 (comment)
>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/
AMr87EoUuLcuTE5k0mXi3kl9MNwyHCvPks5rdl3GgaJpZM4MBRiU>
> .
>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#377 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHgZ5QThkeZd3Re4qve47oNeO1lnknICks5rdmVVgaJpZM4MBRiU>
.
|
75fc3ec
to
6f97e54
Compare
@denfromufa Added the parenthesis. Good to squash-merge? |
you did not address the second comment. @vmuriart will this break if you add:
|
It's not there. It even says on your screen shot that its |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testing
res = MethodTest.TestOverloadedObjectTwo(5, 5) | ||
assert res == "Got int-int" | ||
|
||
res = MethodTest.TestOverloadedObjectTwo(5, "foo") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will this break if you add:
public static string TestOverloadedObjectTwo(int a, string b)
{
return "Got int-string";
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now its there.
Codecov Report
@@ Coverage Diff @@
## master #377 +/- ##
==========================================
+ Coverage 63.27% 63.35% +0.07%
==========================================
Files 61 61
Lines 5226 5226
Branches 860 860
==========================================
+ Hits 3307 3311 +4
+ Misses 1697 1695 -2
+ Partials 222 220 -2
Continue to review full report at Codecov.
|
Added test and its passing as well. |
return "Got object-int"; | ||
} | ||
|
||
public static string TestOverloadedObjectTwo(object a, object b) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't test this method in python
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because you changed the test for it above. I re-added a test for it.
@denfromufa test added and passing as well. |
@vmuriart I'm still surprised that this does not break ;) i approve on my side. in the future we should definitely improve testing all these combinations of arguments by using hypothesis or parametrizing pytest. Let's release v2.3.0.dev1 version after this merge. @filmor @tonyroberts please review! |
@denfromufa I didn't want to introduce |
db6c2ac
to
0ae9c38
Compare
0ae9c38
to
4071aa3
Compare
What does this implement/fix? Explain your changes.
Fixes Method object overloading without breaking changes introduced by #131 and #151.
I added the tests/examples from #131 to the tests to ensure that the behavior didn't get reverted.
Does this close any currently open issues?
Closes #203
Any other comments?
This patch fixes the issue from #203, but
MethodBinder.Bind
needs rewriting since its basically been patched over and over again to fix edge cases. I didn't want to do it as part of thispull_request
since it would affect more than just fixing #203.Checklist
Check all those that are applicable and complete.
AUTHORS