{"action":"created","issue":{"url":"https://api.github.com/repos/pythonnet/pythonnet/issues/296","repository_url":"https://api.github.com/repos/pythonnet/pythonnet","labels_url":"https://api.github.com/repos/pythonnet/pythonnet/issues/296/labels{/name}","comments_url":"https://api.github.com/repos/pythonnet/pythonnet/issues/296/comments","events_url":"https://api.github.com/repos/pythonnet/pythonnet/issues/296/events","html_url":"https://github.com/pythonnet/pythonnet/issues/296","id":192294746,"number":296,"title":"Python.Runtime.Converter support for converting from/to PyObject","user":{"login":"rmadsen-ks","id":24250062,"avatar_url":"https://avatars.githubusercontent.com/u/24250062?v=3","gravatar_id":"","url":"https://api.github.com/users/rmadsen-ks","html_url":"https://github.com/rmadsen-ks","followers_url":"https://api.github.com/users/rmadsen-ks/followers","following_url":"https://api.github.com/users/rmadsen-ks/following{/other_user}","gists_url":"https://api.github.com/users/rmadsen-ks/gists{/gist_id}","starred_url":"https://api.github.com/users/rmadsen-ks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rmadsen-ks/subscriptions","organizations_url":"https://api.github.com/users/rmadsen-ks/orgs","repos_url":"https://api.github.com/users/rmadsen-ks/repos","events_url":"https://api.github.com/users/rmadsen-ks/events{/privacy}","received_events_url":"https://api.github.com/users/rmadsen-ks/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-11-29T14:23:38Z","updated_at":"2016-11-29T14:32:01Z","closed_at":null,"body":"I have a C# class, lets call it MyCSClass, that I intend to be inherited from a Python class and used like this:\r\n```py\r\nclass MyPythonClass(MyCSClass):\r\n   def __init__(self):\r\n      self.MyAttribute = 5\r\n      self.Callback(self)\r\n```\r\nWhen 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:\r\n```cs\r\npublic class MyCSClass {\r\n   protected void Callback(dynamic self){\r\n       Console.WriteLine(\"A dynamic attribute: {0}\", self.MyAttribute);\r\n   }\r\n}\r\n```\r\n\r\nHowever, 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.\r\n\r\nThen I would have to do this instead, which is OK for me:\r\n```cs\r\npublic class MyCSClass {\r\n   protected void Callback(PyObject self){\r\n       Console.WriteLine(\"A dynamic attribute: {0}\", ((dynamic)self).MyAttribute);\r\n   }\r\n}\r\n```\r\n\r\nPython Version: ```Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec  5 2015, 20:32:19) [MSC v.1500 32 bit (Intel)] on win32```\r\nOS: Windows 7 Enterprise\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/pythonnet/pythonnet/issues/comments/263585149","html_url":"https://github.com/pythonnet/pythonnet/issues/296#issuecomment-263585149","issue_url":"https://api.github.com/repos/pythonnet/pythonnet/issues/296","id":263585149,"user":{"login":"denfromufa","id":7870949,"avatar_url":"https://avatars.githubusercontent.com/u/7870949?v=3","gravatar_id":"","url":"https://api.github.com/users/denfromufa","html_url":"https://github.com/denfromufa","followers_url":"https://api.github.com/users/denfromufa/followers","following_url":"https://api.github.com/users/denfromufa/following{/other_user}","gists_url":"https://api.github.com/users/denfromufa/gists{/gist_id}","starred_url":"https://api.github.com/users/denfromufa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/denfromufa/subscriptions","organizations_url":"https://api.github.com/users/denfromufa/orgs","repos_url":"https://api.github.com/users/denfromufa/repos","events_url":"https://api.github.com/users/denfromufa/events{/privacy}","received_events_url":"https://api.github.com/users/denfromufa/received_events","type":"User","site_admin":false},"created_at":"2016-11-29T14:32:01Z","updated_at":"2016-11-29T14:32:01Z","body":"Did you instantiate your Python class MyPythonClass in C#, before accessing\nits members?\n\nOn Tue, Nov 29, 2016, 8:23 AM rmadsen-ks <notifications@github.com> wrote:\n\n> I have a C# class, lets call it MyCSClass, that I intend to be inherited\n> from a Python class and used like this:\n>\n> class MyPythonClass(MyCSClass):\n>    def __init__(self):\n>       self.MyAttribute = 5\n>       self.Callback(self)\n>\n> When an instance of MyPythonClass gets passed to C#, it gets converted to\n> a MyCSClass and is stripped of all the attributes. Even if the method\n> called in CS takes it as a dynamic or PyObject. An example of this could be\n> the *init* method above calling into the following C# code:\n>\n> public class MyCSClass {\n>    protected void Callback(dynamic self){\n>        Console.WriteLine(\"A dynamic attribute: {0}\", self.MyAttribute);\n>    }\n> }\n>\n> However, the instance assigned to 'self' is an MyCSClass and not a dynamic\n> MyPythonClass. Replace dynamic with PyObject and you get an exception. If\n> suggest the the converter should support PyObject, so that callbacks like\n> these are made possible.\n>\n> Then I would have to do this instead, which is OK for me:\n>\n> public class MyCSClass {\n>    protected void Callback(PyObject self){\n>        Console.WriteLine(\"A dynamic attribute: {0}\", ((dynamic)self).MyAttribute);\n>    }\n> }\n>\n> Python Version: Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015,\n> 20:32:19) [MSC v.1500 32 bit (Intel)] on win32\n> OS: Windows 7 Enterprise\n>\n> —\n> You are receiving this because you are subscribed to this thread.\n> Reply to this email directly, view it on GitHub\n> <https://github.com/pythonnet/pythonnet/issues/296>, or mute the thread\n> <https://github.com/notifications/unsubscribe-auth/AHgZ5cpy8-_fnx7cEDYMUXHJBn9yV_q7ks5rDDVrgaJpZM4K_BuF>\n> .\n>\n"}}
{"actor":{"display_login":"denfromufa"}}