Replies: 4 comments 14 replies
|
Yes, variants are a bit of a pain. Ultimately I chose solution based on pythons zen: "Explicit is better than implicit.": the D-Bus type is explicitly encoded. I have a few ideas how to make it more pleasant to work with variants. First, the variant tuple can be overloaded with helper methods or properties. For example, Second, the common structure in D-Bus is dictionary with string keys and variant values. (
There are 8 types of |
|
There is also an unpacking trick: _, is_discoverable = result["/org/bluez/hci0"]["org.bluez.Adapter1"]["Discoverable"]
print(is_discoverable) |
|
|
|
@asmello the latest release |
Uh oh!
There was an error while loading. Please reload this page.
This library is amazing, it's the most ergonomic binding for DBus I've found for the Python language, by a long shot. Everything just makes sense and I'm constantly surprised by good design decisions. But there's one quirk that's been bothering me: why do we get Python tuples for variable-type values encoded in method returns and signals?
For example:
Will print:
Clearly, python-sdbus is able to decode the response to the correct Python type, or the second element in the tuple wouldn't be typed as a
bool. However, it still preserves the low-level DBus type code as the first element. I don't see the benefit of this approach - perhaps it's intended to help write code that handles different possible types in certain fields, like "if string, do this, if bool do that", but for that purpose one can simply usetype(value) is str(or better yetisinstance(value, str)). Further, in this example the type is fixed, so there's never going to be a need for code like that. So to me it feels like this extra context is redundant and adds unnecessary friction. Am I missing something?All reactions