Closed RealOrangeOne closed 6 years ago
Turns out the syntax i'm using for types is only supported in python3.6+, will refactor to use comment-based types instead
Note: this PR is likely to conflict heavily with #41. Since this PR already has some conflicts, I suggest we merge that one first and then rework this PR.
I'm also tempted to use flake8-mypy
to pull the type checking into the linting, though I've not explored whether that actually works before.
@PeterJCLaw @prophile looking through all the changes here, there's a large amount of ambiguity the raw data that comes back from robotd
. Do you know if there's any way we can type explicitly what keys / values to expect in that data, and their types? Or this a limitation Python hasnt solved yet?
Alternatively, we could replace the dictionary with a NamedTuple
, which does support specifying keys and types as we need.
I'm not aware of a way to specify a dictionary with a given set of keys. The reality is that somewhere has to deal with the fact that the JSON blogs are coming back from robotd
are merely dictionaries and don't have type information.
One approach might be to explicitly convert the JSON into NamedTuple
s immediately and then wrap those in our helper classes as needed (is that what you had in mind?), though that feels pretty close to what we're already doing.
It turns out that mypy
is experimenting with a way to have dictionaries with specified keys. It's called TypedDict.
Add type checking, powered by MyPy 🎉
Board
class doesn't implementserial
robot/camera.py:20: error: Signature of "__getitem__" incompatible with supertype "list"
#54