-
Notifications
You must be signed in to change notification settings - Fork 60
Missing Type Annotations #68
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
Comments
I had a look at this, because I though it would make it much easier to implement the tests in #69 . However it turns out, some major refactoring has to be done to make this type safe. If anyone wants to continue on this, I pushed the changes I already did to this branch: https://github.com/theendlessriver13/Adafruit_CircuitPython_GPS/tree/type-annotations . The main thing which causes problems, is the Also many, many checks for The inherited class also causes some trouble: |
@theendlessriver13 I checked out a branch and plugged in what you had come up with and got it passing tests. @FoamyGuy Should we just merge the type annotation changes for now and worry about refactoring/tests in a separate issue? |
Hey, just to make sure you ran (venv) jkittner@ububox:~/workspace/Adafruit_CircuitPython_GPS$ pytest
============================= test session starts ==============================
platform linux -- Python 3.7.12, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
rootdir: /home/jkittner/workspace/Adafruit_CircuitPython_GPS
collected 48 items
tests/adafruit_gps_test.py ............................................. [ 93%]
... [100%]
============================== 48 passed in 0.14s ==============================
(venv) jkittner@ububox:~/workspace/Adafruit_CircuitPython_GPS$ mypy adafruit_gps.py | wc -l
60 |
@theendlessriver13 I had not ran tests with mypy (just pytest). I ran mypy tests and got 45 errors and see what you mean about refactoring. |
I think in the short term we are working to add the type hits to resolve I'm not very familiar with this library or how it operates so I'm a bit unsure about why some of the things have so many different available types. It looks like a good start to me that @theendlessriver13 has got in that commit. I think that named tuples can be used for this purpose as proposed but I'm not 100% certain. If someone picks this up and tries it out that way we can test to ensure no issues on the microcontroller side. |
There are missing type annotations for some functions in this library.
The
typing
module does not exist on CircuitPython devices so the import needs to be wrapped in try/except to catch the error for missing import. There is an example of how that is done here:Once imported the typing annotations for the argument type(s), and return type(s) can be added to the function signature. Here is an example of a function that has had this done already:
If you are new to Git or Github we have a guide about contributing to our projects here: https://learn.adafruit.com/contribute-to-circuitpython-with-git-and-github
There is also a guide that covers our CI utilities and how to run them locally to ensure they will pass in Github Actions here: https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/check-your-code In particular the pages:
Sharing docs on ReadTheDocs
andCheck your code with pre-commit
contain the tools to install and commands to run locally to run the checks.If you are attempting to resolve this issue and need help, you can post a comment on this issue and tag both @FoamyGuy and @kattni or reach out to us on Discord: https://adafru.it/discord in the
#circuitpython-dev
channel.The following locations are reported by mypy to be missing type annotations:
The text was updated successfully, but these errors were encountered: