Fix kwarg func resolution#1136
Conversation
Sorry, something went wrong.
|
Just to note that we have been using this fix for some time and it does appear to work. It is a welcome change from needing to specify long list of args you don't care about. |
Sorry, something went wrong.
lostmsu
left a comment
There was a problem hiding this comment.
Just FYI, there's a much better way to do method resolution (which I hope we will adopt at some point) but it requires lots of rework: C# Binder. I did a simple experiment here: losttech@605c576
We can still take this change in meanwhile.
Sorry, something went wrong.
Yes this wasn't supposed to change the world, simply just to get something that worked 😄 |
Sorry, something went wrong.
ce07727 to
2b98872
Compare
May 12, 2020 08:17
643f7bc to
1dd8725
Compare
May 13, 2020 06:33
lostmsu
left a comment
There was a problem hiding this comment.
Approved, but should wait for post 2.x branch due to the breaking change in behavior around overload resolution ordering.
Sorry, something went wrong.
|
@jmlidbetter we have released 2.5 and |
Sorry, something went wrong.
Sure. I assume just rebasing on top of master is sufficient or is there something else you'd want? |
Sorry, something went wrong.
7caa7ed to
d453159
Compare
June 22, 2020 15:21
|
@lostmsu Ok I have rebased, feel free to check and merge (as appropriate) |
Sorry, something went wrong.
|
Hmm that is strange - when I ran the tests on my machine they all passed.... I will have a look tomorrow. |
Sorry, something went wrong.
|
Seems like the Linux tests have passed ok but are broken on Windows - perhaps there is some slight difference in behaviour on windows. I have limited ability test on windows but I'll see what I can do. |
Sorry, something went wrong.
|
@lostmsu I have not been able to reproduce the test failures. Building on Windows I get the following output: Are you able to repro this issue on windows? |
Sorry, something went wrong.
|
I am not sure what causes the discrepancy, but judging by the code, it seems like the CI build messes up with named parameters. I will try to see if that is correct. However, this also uncovers a bug: if Python passed a named parameter not defined in C#, the overload resolution behavior is incorrect. I suggest to handle that and add a test too. void NoOverloads(int a = 0) {}NoOverloads(c=1) # should fail, because c does not match a |
Sorry, something went wrong.
|
I believe I had originally implemented that behaviour (not submitted onto this branch) but it broke some other tests. I may be misremembering though, I will check tomorrow. |
Sorry, something went wrong.
|
@lostmsu here is the breaking test if you fail when a kwarg is supplied that doesn't appear in the method signature: I haven't done any further investigation into this. I guess there are two ways to proceed: Its up to you, but personally I'm in favour of (1) because (a) having working kwargs (except in the case where you supply extra ones ;) ) is quite a big improvement and (b) python is fairly loose anyway with ducktyping etc etc, in a way all C# methods would have an implicit **kwargs in their signature - it might be possible to throw a warning when extraneous kwargs are given, I don't know. |
Sorry, something went wrong.
|
Are we good to merge this change once the tests have passed? |
Sorry, something went wrong.
|
This looks good to me, @lostmsu are you also fine with merging this? |
Sorry, something went wrong.
Codecov Report
@@ Coverage Diff @@
## master #1136 +/- ##
=======================================
Coverage 87.97% 87.97%
=======================================
Files 1 1
Lines 291 291
=======================================
Hits 256 256
Misses 35 35
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
Sorry, something went wrong.


What does this implement/fix? Explain your changes.
A first run at fixing issue #1097. Currently, the method for selecting which method to use is quite simple and just takes the first function it finds to match. The problem is that the current picking algorithm has no knowledge of kwargs and how many have been supplied or used, i.e. MatchesArgumentCount will return true even if we've supplied some kwargs but the current overload does not require them. Ultimately, this means the first matched method might not be the best.
This small patch aims to rectify this issue by collecting together all the methods for which MatchesArgumentCount returns true and then from these selecting the best match based on the following criteria
It also has some logic to abort in the case where
This stops users in python making ambiguous function calls - see the tests for an example.
Does this close any currently open issues?
#1097
Any other comments?
Feedback please!
Checklist
Check all those that are applicable and complete.
AUTHORSCHANGELOG