-
Notifications
You must be signed in to change notification settings - Fork 100
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 mypy type annotations via monkeytype #344
Add mypy type annotations via monkeytype #344
Conversation
Looks like a lot of work. I'm not used to typing a lot. Anything I should know of your workflow ? |
In the ideal case it's minimal extra work - I've set it up so you can skip most annotations with the caveat that anywhere the type checker can't figure things out it's less able to help catch errors. It'll run the checks right after On your local machine there are a lot of ways to run the checker - easiest is to install the One last explicit callout: even without many annotations |
…after this commit
286b4ff
to
dc0f721
Compare
okay @ChristianTremblay I've got type checks passing for a subset of the codebase and it looks like the unit tests are working too. I'm going to deploy this at a building tomorrow and let it bake for a couple days there and if you have a moment I think this should also be ready for any code-review you want to do. I'll take a pass through it myself too and make sure things look okay on my end. I tried to leave all existing logic intact, except in cases where it was clear that I could make the code accept more input values than it currently does. And please let me know if you have any questions about the type annotations themselves! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, things look good as far as I'm concerned. I tried to call out the reasons for most of the non-annotation code changes both for posterity and to convince myself they were all necessary
@@ -734,7 +724,12 @@ def __repr__(self): | |||
) | |||
) | |||
# Probably disconnected | |||
val = None | |||
return "{}/{} : (n/a) {}".format( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needed to duplicate the string formatting here because it's an error to use {:.2f}
on None
@@ -1187,8 +1183,8 @@ def __init__(self, device, name): | |||
|
|||
self.properties.description = props["description"] | |||
self.properties.units_state = props["units_state"] | |||
self.properties.simulated = "Offline" | |||
self.properties.overridden = "Offline" | |||
self.properties.simulated = (True, None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked and didn't see anywhere checking for these strings, and they seem to conflict with the usual type of Tuple[bool, Optional[int]]
@ChristianTremblay thanks for taking a look! how are you feeling about merging this? is there anything else you'd like me to do infrastructure or documentation wise? |
My plan is to tag a new release from actual develop. |
Thanks ! Let's dive into that now ! |
Just throwing this up here so I can let the tests run against the PR while I keep working, and so that you can take a look at where things are headed if you're curiousso far I've been able to get MonkeyType to produce decent annotations for
I was hoping to get better coverage, but monkey type isn't good about picking up annotations across threads and with the
TaskManager
as the main point of a lot of the functionality I wasn't able to get great annotations automatically. The good news is what I was able to get should be enough to start bootstrapping amypy
run that catches "obviously wrong" bugs like missing function arguments or badly typedstring.format
calls.#closes #324