-
Notifications
You must be signed in to change notification settings - Fork 3
Annotations fix #13
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
Annotations fix #13
Conversation
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.
Thanks for the type annotation submission! I've left some feedback here, let me know if I can help clarify anything!
adafruit_dymoscale.py
Outdated
@@ -21,6 +21,7 @@ | |||
""" | |||
|
|||
import time | |||
import microcontroller |
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.
The CircuitPython interpreter doesn't actually store type annotations like other interpreters do, in an effort to save RAM on the microcontroller. Therefore, it's also best if we can save RAM by not importing libraries used purely for type annotations. Because it's okay to have things used only type annotations be undefined at runtime, we can use a try
/except
block guarded by something that's only available on a computer, like the typing
library. This way, the microcontroller won't end up importing anything in that block, whereas the computer will be able to successfully import everything! If the typing
library isn't used either we can disable a pylint error that would occur for adding it.
In this case, all the imports should look like this:
import time
from pulseio import PulseIn
from micropython import const
try:
import typing # pylint: disable=unused-import
from digitalio import DigitalInOut
import microcontroller
except ImportError:
pass
Let me know if you have any questions!
adafruit_dymoscale.py
Outdated
def __init__(self, data_pin, units_pin, timeout=1.0): | ||
def __init__( | ||
self, | ||
data_pin: microcontroller.pin, |
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'm a little surprised this didn't raise a CI error! data_pin
should be type annotated as microcontroller.Pin
:)
adafruit_dymoscale.py
Outdated
def __init__( | ||
self, | ||
data_pin: microcontroller.pin, | ||
units_pin: microcontroller.pin, |
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.
It's looks like units_pin
is confusingly NOT microcontroller.Pin
but rather DigitalInOut
(from digitalio
)! I'm going to file an issue about this since it's counterintuitive, it may be worth changing the name.
updated per recommendations |
Awesome! Thanks again for the contribution! |
Updating https://github.com/adafruit/Adafruit_CircuitPython_DymoScale to 1.1.9 from 1.1.8: > Merge pull request adafruit/Adafruit_CircuitPython_DymoScale#13 from tcfranks/main
1st attempt at contributing just annotations fixes. hoping this is correctly done!