When an instance of MyPythonClass gets passed to C#, it gets converted to a MyCSClass and is stripped of all the attributes. Even if the method called in CS takes it as a dynamic or PyObject. An example of this could be the init method above calling into the following C# code:
However, the instance assigned to 'self' is an MyCSClass and not a dynamic MyPythonClass. Replace dynamic with PyObject and you get an exception. If suggest the the converter should support PyObject, so that callbacks like these are made possible.
Then I would have to do this instead, which is OK for me:
changed the title [-]Converter support for converting from/to PyObject[/-][+]Python.Runtime.Converter support for converting from/to PyObject[/+]on Nov 29, 2016
On Tue, Nov 29, 2016, 8:23 AM rmadsen-ks ***@***.***> wrote:
I have a C# class, lets call it MyCSClass, that I intend to be inherited
from a Python class and used like this:
class MyPythonClass(MyCSClass):
def __init__(self):
self.MyAttribute = 5
self.Callback(self)
When an instance of MyPythonClass gets passed to C#, it gets converted to
a MyCSClass and is stripped of all the attributes. Even if the method
called in CS takes it as a dynamic or PyObject. An example of this could be
the *init* method above calling into the following C# code:
public class MyCSClass {
protected void Callback(dynamic self){
Console.WriteLine("A dynamic attribute: {0}", self.MyAttribute);
}
}
However, the instance assigned to 'self' is an MyCSClass and not a dynamic
MyPythonClass. Replace dynamic with PyObject and you get an exception. If
suggest the the converter should support PyObject, so that callbacks like
these are made possible.
Then I would have to do this instead, which is OK for me:
public class MyCSClass {
protected void Callback(PyObject self){
Console.WriteLine("A dynamic attribute: {0}", ((dynamic)self).MyAttribute);
}
}
Python Version: Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015,
20:32:19) [MSC v.1500 32 bit (Intel)] on win32
OS: Windows 7 Enterprise
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#296>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHgZ5cpy8-_fnx7cEDYMUXHJBn9yV_q7ks5rDDVrgaJpZM4K_BuF>
.
I get the converted MyCSClass instance inside self.Callback, if the argument is dynamic. If I instead choose PyObject as the type of the argument I just get the following error:
Activity
den-run-ai commented on Nov 29, 2016
rmadsen-ks commented on Nov 29, 2016
In the specific case, __init__ is setting a (non-virtual) property of the base class, but I can confirm that it also happens outside of __init__.
I do this:
I get the converted MyCSClass instance inside self.Callback, if the argument is dynamic. If I instead choose PyObject as the type of the argument I just get the following error:
'TypeError : No method matches given arguments'.
rmadsen-ks commented on Nov 29, 2016
Note pull request #297
den-run-ai commented on Nov 29, 2016
here is related issue with some tips from @tonyroberts:
#94
#94 (comment)