-
Notifications
You must be signed in to change notification settings - Fork 21
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 type hints #46
Add type hints #46
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.
Looks good to me Thanks @tekktrik
Tested successfully on CLUE 7.1.0 Beta 1
My pleasure! |
Updating https://github.com/adafruit/Adafruit_CircuitPython_LSM6DS to 4.2.2 from 4.2.1: > Merge pull request adafruit/Adafruit_CircuitPython_LSM6DS#46 from tekktrik/feature/add-typing > update rtd py version Updating https://github.com/adafruit/Adafruit_CircuitPython_MagTag to 2.1.5 from 2.1.3: > Merge pull request adafruit/Adafruit_CircuitPython_MagTag#68 from RufusVS/tone_frequency_0_fix > Merge pull request adafruit/Adafruit_CircuitPython_MagTag#76 from FoamyGuy/power_before_neopixel_init Updating https://github.com/adafruit/Adafruit_CircuitPython_PYOA to 2.5.0 from 2.4.1: > Merge pull request adafruit/Adafruit_CircuitPython_PYOA#25 from lesamouraipourpre/remove-old-refresh > update rtd py version
@@ -64,12 +64,18 @@ | |||
from adafruit_register.i2c_bits import RWBits | |||
from adafruit_register.i2c_bit import RWBit | |||
|
|||
try: | |||
from typing import Tuple, Optional | |||
from busio import I2C |
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.
Sorry for the late comment -- but I am confused by this.
If the import of typing fails, won't this then ignore the import of I2C?
Shouldn't the typing import be the last import.
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.
@jerryneedell No worries. You are correct. if typing
fails to import then I2C
will get ignored.
In this case the only usage of the I2C object that is imported here was for adding type information to some function arguments. CircuitPython will not use that typing information anyway (and will not crash if there are missing imports related to it).
So we use the import typing
first in order to determine if the library is currently being used on a microcontroller essentially. If typing
import fails we think it is a microcontroller and therefore we don't need the rest of the imports that are used only for typing either. Putting them after import typing
and thus skipping them in environments without typing
will save a little bit of memory I think. If I2C
did get imported on microcontrollers it would consume a little memory and not actually do anything in this scope.
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.
Thank you for the explanation.
PR to add type hints per Issue #44