-
Notifications
You must be signed in to change notification settings - Fork 748
Pythonnet 2.1 not identifying System.Object type #203
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
Comments
Possibly related to #187 |
Tried build before and after #176, both still have this bug present. |
@denfromufa just tried your suggestion and it semi-works. It passes through |
did you try |
@vmuriart I think for your case, the overloading resolution in pythonnet could be improved by checking isinstance("string",System.Object) which corresponds to |
I see your point. I'm not familiar enough with the source code in relation to how pythonnet decides which method to call. |
@vmuriart python and .net types cannot be directly mapped to c-types due to much more complicated type system. all conversions are manually taken care for basic types in pythonnet: https://github.com/pythonnet/pythonnet/blob/master/src/runtime/converter.cs |
The problem that I am having with it at the moment is that quite a few of the libraries have broken with |
Can we just look at all types of incompatibilities that you experience with Then we should really think whether the wrong results from On Sunday, April 17, 2016, Vik notifications@github.com wrote:
|
@vmuriart @denfromufa my preference would be to attempt to fix 2.1 to fix the backward compatibilities, rather than just roll back. If it's just adding a case so that System.Object matches everything then hopefully that wouldn't be a big change, would it? Or are there more problems than that? |
@vmuriart would it be easy for you to add a few unit tests to check what's currently breaking? I think it's better to show the build currently as broken, if the only reason it's not showing as broken now is just lack of test coverage! :) |
@tonyroberts so match even python |
@denfromufa it may be more robust to check for base classes and interfaces of the managed class mapped to the Python type |
@tonyroberts @vmuriart can you provide me with few examples which need to be fixed? |
I'll write up a couple tests for the issue On Monday, April 18, 2016, denfromufa notifications@github.com wrote:
|
@denfromufa try this test. |
what would you expect for this test on python side when calling this CLR On Mon, Apr 18, 2016 at 2:47 PM, Vik notifications@github.com wrote:
|
Just verified that this used to work on the 2.0 version with this commit vmuriart/pythonnet@e5c4e74...f77695f The test is pretty simple, I don't particularly care about the output just that the behavior still works. |
i just noticed the python code, sorry for confusion. What if the overloaded method with System.String is added? Then your tests On Mon, Apr 18, 2016 at 3:11 PM, Vik notifications@github.com wrote:
|
@vmuriart your tests are not complete - you do not check that correct overloaded method is selected. Some sort of asserting is required. |
Correct. I meant the test as a proof of concept to demonstrate how to repeat the bug and that the behavior worked on the old version. |
@vmuriart sorry - I'm still not clear, what do you expect, if overloaded method with System.String argument is added? this is definitely not bug, since no agreed upon test is available for this scenario as of yet and implicit overloading is not supported anymore. |
@denfromufa if an overload with argument type System.String was added then that would be used instead when a string was passed. If a non string type (but one still deriving from System.Object, e.g. System.Int32) was used then the object method would be used. There's no implicit conversion from one type to another going on, a string is an object so the overload is valid. Here's a link that might be useful |
@tonyroberts thank you for this explanation. Let me now write this code for base classes. |
@tonyroberts thanks for explaining it! I was struggling on getting the right words together. |
patch for pythonnet#203 - not best solution though.
Just an idea: Maybe Roslyn can help with issues like these. If we can re-use their (or parts of their) overload resolution logic we don't need to reimplement the spec. On the other hand: Going a different route is valid as well. In F# you actually need to mark implicit casts with an operator (while this case would still work as everything is an object) |
@matthid i was thinking about re-using roslyn as well, but then we have a lot of python-specific logic. what do you mean by "On the other hand: Going a different route is valid as well"? |
What I meant was that pythonnet doesn't need to mirror C# overload resolution logic. Instead it is completely fine to define its own (possibly simpler) logic. For this issue I'd say that most people expect this to work. But IMHO it could be closed as "wontfix" as well (and say that "by-design" types need to match exactly). It depends on what spec/design guideline this project follows. As you are trying to mirror ironpython(?) this is most likely a bug :) |
patch for #203 - not best solution though.
patch for pythonnet#203 - not best solution though.
patch for pythonnet#203 - not best solution though.
patch for pythonnet#203 - not best solution though.
patch for pythonnet#203 - not best solution though.
patch for pythonnet#203 - not best solution though.
patch for pythonnet#203 - not best solution though.
patch for pythonnet#203 - not best solution though.
it appears that precedence of types is simplified version of Jython, found by @vmuriart 👍 https://github.com/pythonnet/pythonnet/blob/master/src/runtime/methodbinder.cs#L170 I'm not sure how this compares to IronPython, but likely very similar due to the same author: |
Fun fact on the history of Jim and IronPython.
|
I'm not sure how the tests wouldn't have caught this bug.
I have a
.net
class that has the functionAddQuery
with the following method signatures.where
QueryType
is another custom object type.On
2.0
and2.1dev1
the function works as expected.QueryType
object toAddQuery
and it would call the first method.AddQuery
with astring
orint
would use the second method and process them.On
2.1.0
and the earliest archived copy inappveyor
this behavior changed.QueryType
object toAddQuery
still works.string
type toAddQuery
errors withNo method matches given arguments
I've tested on
Python 2.7
,Python 3.5
both x64.Looks like Pythonnet is no longer identifying
string
int
and other types to be of typeSystem.Object
as well.The text was updated successfully, but these errors were encountered: