Skip to content
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

Merged
merged 2 commits into from
Dec 10, 2021
Merged

Add type hints #46

merged 2 commits into from
Dec 10, 2021

Conversation

tekktrik
Copy link
Member

PR to add type hints per Issue #44

@tannewt tannewt requested a review from a team December 10, 2021 17:45
Copy link
Contributor

@FoamyGuy FoamyGuy left a 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

@FoamyGuy FoamyGuy merged commit f94ef67 into adafruit:main Dec 10, 2021
@tekktrik
Copy link
Member Author

My pleasure!

adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Dec 11, 2021
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
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

@tekktrik tekktrik mentioned this pull request Dec 14, 2021
16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants