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 typing #19

Merged
merged 7 commits into from
Oct 30, 2021
Merged

Add typing #19

merged 7 commits into from
Oct 30, 2021

Conversation

tekktrik
Copy link
Member

Addresses Issue #18

@@ -28,6 +28,7 @@
import digitalio
import adafruit_bus_device.spi_device as spi_device


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will have to import the values being typed against, e.g. microcontroller.Pin in a try block like can be seen in the issue. For another example see: adafruit/Adafruit_CircuitPython_NeoPixel@eab2911

I believe it will also be required for ReadableBuffer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks for the feedback! I'll resubmit with those imports.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gamblor21 - It's giving me a failure for pylint because of the unused typing module. Any advice on how to proceed? Will using those imports eat up too much RAM, or should I just remove the try statement in this case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Foamyguy answered this below with the pylint ignore comment? And I do not see the imports would eat away at RAM. I'm guessing in almost all cases if you import the library that requires those types, you will require the imports as well. Sorry was busy the last couple days so didn't reply right away.

@@ -28,6 +28,14 @@
import digitalio
import adafruit_bus_device.spi_device as spi_device

try:
import typing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add a pylint ignore comment for this import.

import typing  # pylint: disable=unused-import

The importing module doesn't get used from the rest of code, but it does serve the purpose of determining if the environment has typing.

@tekktrik
Copy link
Member Author

I believe I'm going to have the same issue with '_typing' as I just mentioned in adafruit/Adafruit_CircuitPython_HT16K33#92 so I'll update both at the same time!

@FoamyGuy
Copy link
Contributor

Once we figure out the solution for HT16K33 we can apply the same thing here.

@@ -131,14 +148,14 @@ def gpio(self):
return self._gpio

@gpio.setter
def gpio(self, val):
def gpio(self, val: ReadableBuffer):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use bytearray here instead of ReadableBuffer I think.

@tekktrik
Copy link
Member Author

Made those changes. Also changed some things around after running pylint, I think it was just how spi_device gets imported.

@FoamyGuy
Copy link
Contributor

This one will need formatted with Black code formatter again. There is a guide page that shows how to set up a tool called pre-commit to check all of the CI checks locally if you are interested in trying that out:
https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/check-your-code

@tekktrik
Copy link
Member Author

Oh awesome, yeah, thanks

@tekktrik
Copy link
Member Author

Is there a way to get the pylint examples to not fail on pre-commit? Is it because I work on windows that I get "Executable /usr/bin/env not found"?

@FoamyGuy
Copy link
Contributor

I'm not sure. I don't think I've seen that error specifically. Does that happen when you run pre-commit run -all-files or pre-commit install? or something different.

It does look like it's passing now though 🎉

adafruit_74hc595.py Outdated Show resolved Hide resolved
@tekktrik
Copy link
Member Author

I get it on pre-commit run --all-files and also when I try to commit with it installed via pre-commit install

@FoamyGuy
Copy link
Contributor

I get it on pre-commit run --all-files and also when I try to commit with it installed via pre-commit install

I don't have much experience with running the tools on Windows. Maybe try asing in the #circuitpython-dev channel on the discord: https://adafru.it/discord someone there may have more insight into that error.

@tekktrik
Copy link
Member Author

Got it, thank you for all the help for a newbie!

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. Thank you @tekktrik !

@FoamyGuy FoamyGuy merged commit b8b3618 into adafruit:main Oct 30, 2021
@tekktrik tekktrik mentioned this pull request Nov 2, 2021
9 tasks
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Nov 3, 2021
Updating https://github.com/adafruit/Adafruit_CircuitPython_74HC595 to 1.3.1 from 1.3.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_74HC595#19 from tekktrik/feature/add-typing
  > fix branch name on conduct link
  > add docs link to readme
  > Globally disabled consider-using-f-string pylint check
  > Moved default branch to main
  > Moved CI to Python 3.7
  > Added help text and problem matcher
  > Added pull request template

Updating https://github.com/adafruit/Adafruit_CircuitPython_AM2320 to 1.2.8 from 1.2.7:
  > Merge pull request adafruit/Adafruit_CircuitPython_AM2320#22 from tylercrumpton/add-type-hints
  > add docs link to readme
  > Globally disabled consider-using-f-string pylint check
  > Moved default branch to main
  > Moved CI to Python 3.7
  > Added help text and problem matcher
  > Added pull request template

Updating https://github.com/adafruit/Adafruit_CircuitPython_DHT to 3.6.3 from 3.6.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_DHT#76 from tylercrumpton/add-type-hints
  > add docs link to readme

Updating https://github.com/adafruit/Adafruit_CircuitPython_HT16K33 to 4.1.6 from 4.1.5:
  > Merge pull request adafruit/Adafruit_CircuitPython_HT16K33#92 from tekktrik/feature/add-typing
  > add docs link to readme
  > Globally disabled consider-using-f-string pylint check
  > Moved default branch to main
  > Moved CI to Python 3.7
  > Added help text and problem matcher
  > Added pull request template
  > "Increase duplicate code check threshold "

Updating https://github.com/adafruit/Adafruit_CircuitPython_PM25 to 2.1.5 from 2.1.4:
  > Merge pull request adafruit/Adafruit_CircuitPython_PM25#20 from process1183/type_annotations
  > add docs link to readme
  > Globally disabled consider-using-f-string pylint check
  > Moved default branch to main
  > Moved CI to Python 3.7
  > Added help text and problem matcher
  > Added pull request template

Updating https://github.com/adafruit/Adafruit_CircuitPython_SSD1305 to 1.3.7 from 1.3.6:
  > Merge pull request adafruit/Adafruit_CircuitPython_SSD1305#14 from tylercrumpton/add-type-hints
  > add docs link to readme
  > Globally disabled consider-using-f-string pylint check
  > Moved default branch to main
  > Moved CI to Python 3.7
  > Added help text and problem matcher
  > Added pull request template
  > "Increase duplicate code check threshold "

Updating https://github.com/adafruit/Adafruit_CircuitPython_ST7735R to 1.5.1 from 1.5.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_ST7735R#27 from FoamyGuy/type_info
  > add docs link to readme
  > Globally disabled consider-using-f-string pylint check

Updating https://github.com/adafruit/Adafruit_CircuitPython_WS2801 to 0.10.7 from 0.10.6:
  > Merge pull request adafruit/Adafruit_CircuitPython_WS2801#23 from rhooper/main
  > fix branch name in conduct link
  > add docs link to readme
  > Globally disabled consider-using-f-string pylint check
  > Moved default branch to main
  > Moved CI to Python 3.7
  > Added help text and problem matcher
  > Added pull request template
  > "Increase duplicate code check threshold "

Updating https://github.com/adafruit/Adafruit_CircuitPython_Display_Notification to 0.9.5 from 0.9.4:
  > Merge pull request adafruit/Adafruit_CircuitPython_Display_Notification#9 from tekktrik/fix/add-blinka-requirement
  > add docs link to readme
  > Globally disabled consider-using-f-string pylint check
  > Moved default branch to main
  > Moved CI to Python 3.7
  > Added help text and problem matcher
  > Added pull request template
  > "Increase duplicate code check threshold "

Updating https://github.com/adafruit/Adafruit_CircuitPython_LED_Animation to 2.5.7 from 2.5.6:
  > Merge pull request adafruit/Adafruit_CircuitPython_LED_Animation#84 from rhooper/sparkle-mask
  > Merge pull request adafruit/Adafruit_CircuitPython_LED_Animation#78 from plugowski/master
  > add docs link to readme

Updating https://github.com/adafruit/Adafruit_CircuitPython_Logging to 3.7.0 from 1.2.9:
  > Merge pull request adafruit/Adafruit_CircuitPython_Logging#22 from tekktrik/feature/add-file-handler

Updating https://github.com/adafruit/Adafruit_CircuitPython_Waveform to 1.3.7 from 1.3.6:
  > Merge pull request adafruit/Adafruit_CircuitPython_Waveform#22 from rhooper/main
  > add docs link to readme
  > Globally disabled consider-using-f-string pylint check
  > Moved default branch to main
  > Moved CI to Python 3.7
  > Added help text and problem matcher
  > Added pull request template
  > "Increase duplicate code check threshold "

Updating https://github.com/adafruit/Adafruit_CircuitPython_WSGI to 1.1.5 from 1.1.4:
  > Merge pull request adafruit/Adafruit_CircuitPython_WSGI#10 from rhooper/main
  > fix branch name in conduct link
  > add docs link to readme
  > Globally disabled consider-using-f-string pylint check
  > Moved default branch to main
  > Moved CI to Python 3.7
  > Added help text and problem matcher
  > Added pull request template
  > "Increase duplicate code check threshold "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants