driver: add initial type hints for common driver code - #1946
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1946 +/- ##
======================================
Coverage 61.0% 61.0%
======================================
Files 182 182
Lines 14899 14901 +2
======================================
+ Hits 9095 9103 +8
+ Misses 5804 5798 -6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
2631215 to
8411023
Compare
Emantor
left a comment
There was a problem hiding this comment.
Changes look good to me, do you also want to add a ty check run to this PR for the CI or is it too early for that?
Thanks for your approval! I'd be happy to add such check to CI. If you don't mind, I'd do that in a separate commit. EDIT: just re-pushed to get the commit of this PR verified. |
8411023 to
5efa0dc
Compare
Add `ty` as a development dependency and configure it to check one initial driver module. Annotate `labgrid.driver.common` while leaving existing attrs-based exception behavior unchanged. Signed-off-by: Rainer Poisel <rainer@embedded-focus.com>
5efa0dc to
427d66f
Compare
| super().__attrs_post_init__() | ||
| if self.target is None: | ||
| raise BindingError("Drivers can only be created on a valid target") | ||
| raise BindingError("Drivers can only be created on a valid target") # ty: ignore[too-many-positional-arguments] |
There was a problem hiding this comment.
So we need to mark each instantiation of an attr.s class like that? I don't think that scales..
Doesn't mypy work better with that?
There was a problem hiding this comment.
AFAIR mypy had the same issues, thats why we never got anywhere with the initial type hints.
There was a problem hiding this comment.
In the separate PR that will add ty as a dependency incl. CI check, I'll disable the too-many-positional-arguments check for the whole repo until there is clean support for attrs classes.
At the moment, ty does not really support attrs. See astral-sh/ty#2404 if you want to learn more.
No, I didn't because I want to do that in a separate commit.
I would leave it for now. Now that you mention that: I think I will even remove the |
Co-authored-by: Bastian Krause <bst@pengutronix.de> Signed-off-by: Rainer Poisel <rainer.poisel@gmail.com>
Co-authored-by: Bastian Krause <bst@pengutronix.de> Signed-off-by: Rainer Poisel <rainer.poisel@gmail.com>
Co-authored-by: Bastian Krause <bst@pengutronix.de> Signed-off-by: Rainer Poisel <rainer.poisel@gmail.com>
Signed-off-by: Rainer Poisel <rainer@embedded-focus.com>
The ty type checker will be added in a subsequent PR. Signed-off-by: Rainer Poisel <rainer@embedded-focus.com>
Description
This PR starts adding type annotations incrementally, as discussed in #1945.
It adds
tyas a development dependency and configures it to check a small initial module of the codebase:labgrid/driver/common.py.Verified locally with:
Checklist