- Notifications
You must be signed in to change notification settings - Fork768
Stricter coversion of primitive Python types toSystem.Object#1958
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
…, and `str` to corresponding .NET primitive typesfixespythonnet#1957
lostmsu commentedSep 30, 2022
This should go into 3.0.0 |
filmor commentedSep 30, 2022
3.0.0 ia released already and I disagree with the proposed behavior. I don't get why you are insisting that this is the "correct" way. If a type is derived from another that clearly indicates an "is a" relation, and evidently people got really confused with the behavior we had in the RCs. I totally agree that we should allow overriding this behavior, I disagree with this approach. |
lostmsu commentedOct 1, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@filmor I don't think you got the scenario. It is not about converting Without this change codecs can't be applied because the conversion to primitives takes priority. Converting |
lostmsu commentedOct 5, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@filmor any comments? Due to the above type information loss either this change needs to be accepted to be able to avoid the issue, or the checks need to move below codec application, which can lead to poorly predictable behavior for codecs that claim to be able to decode |
filmor commentedOct 5, 2022
I'm on vacation right now, will check once I'm back. I find it unlikely that I will accept the PR as it stands, but I'll need to be a bit around with it. |
lostmsu commentedOct 7, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@filmor I think I came up with a good demonstration why this PR should be accepted as is. Without it the following code will work for any numpy value except [ForbidPythonThreads]dynamicCentroid(dynamicvalue)=>value-value.mean(); v=numpy.float32(42)print(Centroid(v))# OKv=numpy.float64(42)# RuntimeBinderException: System.Double does not have .mean()print(Centroid(v)) Codecs are not involved here, so the conversion should not happen regardless of the state of the codecs. |
filmor commentedOct 7, 2022
With that argument, we should forbid /any/ conversion of primitive Python types to |
lostmsu commentedOct 8, 2022
@filmor I don't think it applies to primitive types, as
|
filmor commentedOct 15, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I'm not sure what you mean by that. How many would be "too many"?
Exactly. And I think instead of breaking working code further, we should just make this an option. There are (to me) two kinds of functions for which this is relevant:
For the latter, I don't see any reason why these shouldn't just take a For the former, things might be a bit more tricky, but I'd suggest (in general) to just expose more of the conversion machinery publicly and solve this case using a |
lostmsu commentedOct 18, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Then you proceed to name a reason. I'd also say that the only good reason to have a |
filmor commentedOct 19, 2022
That is not the point.
And I also give a way to make this work by being more explicit. That is the gist of a lot of the changes for Python.NET 3 (that you also introduced yourself!). There is no way to distinguish |
lostmsu commentedOct 19, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Point is why even do it this way in the first place? What is the scenario where |
filmor commentedOct 19, 2022
We agree here. I just want to not break the behaviour right now, and if we break it, remove all special-casing in one go instead of keeping it for (some) primitives. If we want to keep things simple, we can make this a runtime configuration parameter. |
lostmsu commentedOct 19, 2022
@filmor as far as I am concerned, this issue is a consequence of introducing last minute changes to 3.0 before release. And considering its use case rarity, it should be considered a bug in 3.0.0, so should be fixed in 3.0.1. If you are unhappy about interface breakage, 3.0.0 should be yanked. |
filmor commentedOct 20, 2022
It is not. As said, with the change as it stands, I'm not okay and I think we have discussed it enough now. The correct thing to do would be to not convert at all for |
lostmsu commentedOct 20, 2022
@filmor I don't think we need a global toggle for this. There was another option:
That way this could be fixed with a codec. |
…s when target type is System.Objectuseful to be able to change what numpy.float64 is converted torelated topythonnet#1957this is an alternative topythonnet#1958
filmor commentedOct 28, 2022
Closing this in favour of#1986. |
…s when target type is System.Objectuseful to be able to change what numpy.float64 is converted torelated topythonnet#1957this is an alternative topythonnet#1958
When trying to convert to
System.Object, only convertfloat,bool, andstrto corresponding .NET primitives types. DoNOT convert instances of types derived from them.What does this implement/fix? Explain your changes.
This changes
Converterto perform exact type checks when target type isSystem.ObjectDoes this close any currently open issues?
fixes#1957
Checklist
Check all those that are applicable and complete.