-
Notifications
You must be signed in to change notification settings - Fork 20
Adding type annotations and fixing float incompatibility #67
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
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 working on this @RossK1!
Looks mostly good to me, but I noted a few things I think we can change.
simpleio.py
Outdated
self.iopin = digitalio.DigitalInOut(pin) | ||
self.iopin.switch_to_output(**kwargs) | ||
|
||
@property | ||
def value(self): | ||
def value(self) -> Any: |
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 think this could be bool
instead of Any
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.
Corrected in the latest push together with the next change request.
The issue here is that mypy will complain. Technically self.iopin.value
will return a boolean as it evaluates from the below function in the digitalio package. However, until that function is type-hinted to return bool, mypy thinks it is returning Any, and will hence complain as shown.
@property
def value(self):
"""The Digital Pin Value"""
return self._pin.value() == 1
simpleio.py:219: error: Returning Any from function declared to return "bool" [no-any-return]
simpleio.py:241: error: Returning Any from function declared to return "bool" [no-any-return]
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.
Ahh, that makes sense. Thank you.
That is okay to have this one raising an error here for that reason. We'll get digitalio typed eventually as well to resolve this. I wonder where it would pull types for built-in modules from, the stubs package, or perhaps the Blinka implementation.
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.
Latest version looks good to me. Thanks again @RossK1!
Updating https://github.com/adafruit/Adafruit_CircuitPython_ATECC to 1.2.17 from 1.2.15: > Merge pull request adafruit/Adafruit_CircuitPython_ATECC#33 from FoamyGuy/fix_docs > Merge pull request adafruit/Adafruit_CircuitPython_ATECC#31 from brass75/issue_25/missing-typehints > Add upload url to release action > Add .venv to .gitignore > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_LC709203F to 2.3.0 from 2.2.11: > Merge pull request adafruit/Adafruit_CircuitPython_LC709203F#25 from jrrickerson/config_voltage_alarm Updating https://github.com/adafruit/Adafruit_CircuitPython_RockBlock to 1.3.12 from 1.3.11: > Merge pull request adafruit/Adafruit_CircuitPython_RockBlock#30 from zachariahpifer/add-type-annotations > Add upload url to release action > Add .venv to .gitignore Updating https://github.com/adafruit/Adafruit_CircuitPython_TCS34725 to 3.3.17 from 3.3.16: > Merge pull request adafruit/Adafruit_CircuitPython_TCS34725#42 from zemyblue/feat/support_tcs34727 > Add upload url to release action > Add .venv to .gitignore Updating https://github.com/adafruit/Adafruit_CircuitPython_Touchscreen to 1.2.1 from 1.2.0: > Merge pull request adafruit/Adafruit_CircuitPython_Touchscreen#25 from CedarGroveStudios/patch-1 Updating https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k to 2.5.0 from 2.4.2: > Merge pull request adafruit/Adafruit_CircuitPython_Wiznet5k#95 from BiffoBear/new_dhcp_state_machine Updating https://github.com/adafruit/Adafruit_CircuitPython_MacroPad to 2.2.0 from 2.1.8: > Merge pull request adafruit/Adafruit_CircuitPython_MacroPad#44 from kalehmann/feature/display_sleep > Add upload url to release action > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_SimpleIO to 3.0.10 from 3.0.9: > Merge pull request adafruit/Adafruit_CircuitPython_SimpleIO#67 from RossK1/adding_type_hints > Add upload url to release action > Add .venv to .gitignore Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA: > Updated download stats for the libraries
Added type annotations and supporting imports.
One issue relates to where a float could be generated in the "tone" function and later used to construct and array and a range. In both cases the math.floor function was implemented to ensure that only integers reach these lines.