-
Notifications
You must be signed in to change notification settings - Fork 60
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add options to explicitly specify DBus signatures in decorators #111
base: master
Are you sure you want to change the base?
Conversation
The tests are passing, but the flake8 check is erroring on a bunch of things - also in files I haven't touched at all. I can easily fix the formatting across all files but I don't know if you would like that on top of this PR? |
It was caused by a yapf update. Take b74742e and it should work with no changes. |
The builtin @decorator property recreates itself when the .setter, .getter or .deleter child-decorators are used. This meant that the introspection meant for the getter was also being applied to the setter. I added a guard for this situation to exit early, and instead copy the already introspected properties over from the getter.
b2ead3c
to
c4fb5c7
Compare
Okay, now all the tests and linting checks are passing |
@acrisci did you have a chance to look at this PR? Is this a feature you are interested in, and if so is there anything I can do to help getting it merged? |
This sounds very attractive! Does this change also enable the use of named arguments in the client? We like to use those not to enable out of order argument passing or optional arguments, but just clarity to the next code maintainer on what the call is doing. Currently dbus_next doesn't work if you use them. e.g. If I try to call the above like this, it doesn't work: |
I don't believe that DBus itself supports optional arguments. At least, I think that it requires that all argument lists must be concretely typed. The normal way of supplying optional arguments is something with passing a dict or a "Varying". I guess that you could argue that a "high level" abstraction interface shouldn't necessarily be limited by limitations from further down in the stack, but I guess in this case the maintainers have decided that it is more sensible for a DBus interface to follow this core rule of DBus communication. Anyway, this PR doesn't really have anything to do with any of that - it was mostly something I did to enable dbus-next to be used in projects that check type annotation with mypy or pyright. |
I would really appreciate some traction on this for the same reason: it lets the type annotations be used as type annotations as opposed to being hijacked for a semantic purpose. mypy doesn't really like that. |
This adds options to the
@method
,@dbus_property
and@signal
decorators that can be used to explicitly specify the DBus signature.While I find the use of the type annotations to specify the DBus signatures to be very readable, it has the downside that ordinary Python type annotations cannot be used when creating DBus interfaces. Also, as discussed in #78, any type checker (such as mypy or pyright) that tries to validate types will complain about the DBus annotations, and some editors will flag the annotations as errors because of this.
This PR allows the use of "normal" type annotations by allowing the signatures to be specified in the decorators, like this:
If the signature is specified directly in the decorator the method and return type annotations are not inspected, but I have been careful to ensure that the correct data structures are still created for argument lists and signature trees.
I have added some testcases to the tests in test_decorators to validate the new feature.