Title: Using the __init__() method to pass objects to the server implementation of an interface? · python-sdbus/python-sdbus · Discussion #115 · GitHub
Open Graph Title: Using the __init__() method to pass objects to the server implementation of an interface? · python-sdbus/python-sdbus · Discussion #115
X Title: Using the __init__() method to pass objects to the server implementation of an interface? · python-sdbus/python-sdbus · Discussion #115
Description: Using the __init__() method to pass objects to the server implementation of an interface?
Open Graph Description: Hi! When implementing the server side of an interface it seems to me to be convenient to be able to pass references etc. to an interface using the def __init__(self, ...) call. But I'm having troub...
X Description: Hi! When implementing the server side of an interface it seems to me to be convenient to be able to pass references etc. to an interface using the def __init__(self, ...) call. But I'm having t...
Opengraph URL: https://github.com/python-sdbus/python-sdbus/discussions/115
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"QAPage","mainEntity":{"@type":"Question","name":"Using the __init__() method to pass objects to the server implementation of an interface?","text":"Hi!
\nWhen implementing the server side of an interface it seems to me to be convenient to be able to pass references etc. to an interface using the def __init__(self, ...) call.
\nBut I'm having trouble to get this to work, as I get the error:
\n... object has no attribute '_dbus'\n
\nback.
\nAn example:
\nfrom sdbus import (DbusInterfaceCommonAsync, dbus_method_async,\n request_default_bus_name_async)\nfrom asyncio import new_event_loop\n\nclass HelloInterface(\n DbusInterfaceCommonAsync,\n interface_name='org.example.interface'\n):\n def __init__(self, hello):\n self.hello = hello\n\n @dbus_method_async(\n input_signature='s',\n result_signature='s',\n )\n async def hello(self, string: str) -> str:\n return self.hello.say_hello_back(str)\n\nclass Hello:\n def say_hello_back(str):\n return \"Hello {str}!\"\n\nhello = Hello()\ni = HelloInterface(hello)\n\nasync def startup() -> None:\n await request_default_bus_name_async('org.example.test')\n i.export_to_dbus('/')\n\nloop = new_event_loop()\n\nloop.run_until_complete(startup())\nloop.run_forever()\n
\nThis gives the error:
\nTraceback (most recent call last):\n File \"/tmp/test/hello_interface.py\", line 32, in <module>\n loop.run_until_complete(startup())\n ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^\n File \"/usr/lib/python3.13/asyncio/base_events.py\", line 725, in run_until_complete\n return future.result()\n ~~~~~~~~~~~~~^^\n File \"/tmp/test/hello_interface.py\", line 28, in startup\n i.export_to_dbus('/')\n ~~~~~~~~~~~~~~~~^^^^^\n File \"/usr/lib/python3/dist-packages/sdbus/dbus_proxy_async_interface_base.py\", line 322, in export_to_dbus\n local_object_meta = self._dbus\n ^^^^^^^^^^\nAttributeError: 'HelloInterface' object has no attribute '_dbus'\n
\nObviously something is missing in the def __init__() method, but I've not been able to find out what it could be.
\nAny pointers?
","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"It is a different error caused by the fact you are using hello both as attribute and method. You have to rename one of them. For example, call attribute _hello:
\n def __init__(self, hello):\n super().__init__()\n self._hello = hello
","upvoteCount":0,"url":"https://github.com/python-sdbus/python-sdbus/discussions/115#discussioncomment-14910541"}}}
| route-pattern | /_view_fragments/Voltron::DiscussionsFragmentsController/show/:user_id/:repository/:discussion_number/discussion_layout(.:format) |
| route-controller | voltron_discussions_fragments |
| route-action | discussion_layout |
| fetch-nonce | v2:4a1e5bf3-f075-b8cc-1c6d-453a2f913f7d |
| current-catalog-service-hash | 9f0abe34da433c9b6db74bffa2466494a717b579a96b30a5d252e5090baea7be |
| request-id | ACD4:A24B6:D61A:106E0:698D12E9 |
| html-safe-nonce | bbe96979d68dcc1390dcc70dc9a008b9420f4a318994d9f266c532bf256fa42a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQ0Q0OkEyNEI2OkQ2MUE6MTA2RTA6Njk4RDEyRTkiLCJ2aXNpdG9yX2lkIjoiMTAzOTE1MDA4NjE1NDQyNTA2NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6c601dc81bcd63d3f5235ef1de03b4a7000c74310e245f456bbf2f255ecfea73 |
| hovercard-subject-tag | discussion:9119388 |
| github-keyboard-shortcuts | repository,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/Voltron::DiscussionsFragmentsController/show/python-sdbus/python-sdbus/115/discussion_layout |
| twitter:image | https://opengraph.githubassets.com/7a4153bf31bbb4e88464d6dcca70c4daadb0fe0d4d69b10d6ea78c7486abecf8/python-sdbus/python-sdbus/discussions/115 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7a4153bf31bbb4e88464d6dcca70c4daadb0fe0d4d69b10d6ea78c7486abecf8/python-sdbus/python-sdbus/discussions/115 |
| og:image:alt | Hi! When implementing the server side of an interface it seems to me to be convenient to be able to pass references etc. to an interface using the def __init__(self, ...) call. But I'm having troub... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | c25395580e1e3bf82d705e0982a1b24255366088720fef945f1493d5e3e67954 |
| turbo-cache-control | no-preview |
| go-import | github.com/python-sdbus/python-sdbus git https://github.com/python-sdbus/python-sdbus.git |
| octolytics-dimension-user_id | 88226657 |
| octolytics-dimension-user_login | python-sdbus |
| octolytics-dimension-repository_id | 311269257 |
| octolytics-dimension-repository_nwo | python-sdbus/python-sdbus |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 311269257 |
| octolytics-dimension-repository_network_root_nwo | python-sdbus/python-sdbus |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 94219dcb9c044792ec271fd5b23c73419858bef7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width