Skip to content

Add type annotations #73

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

Merged
merged 6 commits into from
May 9, 2022
Merged

Conversation

jcerise
Copy link
Contributor

@jcerise jcerise commented May 2, 2022

Addresses issue #65

Adds type annotations across the file.

Items of note:

  • I inferred types to the best of my ability in a few areas, any feedback on incorrect types is appreciated
  • Bare asterisk usage in function signature triggers mypy to say that the signature is missing an annotation, not quite sure how to properly suppress that.

Copy link
Member

@tekktrik tekktrik left a comment

Choose a reason for hiding this comment

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

Awesome job with this, what a doozy! 😰

Feedback and comments attached, let me know if I can help explain anything!

@tekktrik
Copy link
Member

tekktrik commented May 2, 2022

Also, the bare asterisk signifies that any arguments following it, must be keyword-only, so it doesn't make sense to type annotate it since it's more of a sentinel character than actual argument. But I don't know how to argue with (or otherwise suppress) mypy! Maybe there is a suitable type annotation for it, but if so, we haven't been using it so no worries!

@tekktrik tekktrik linked an issue May 2, 2022 that may be closed by this pull request
18 tasks
@jerryneedell
Copy link
Contributor

I do hope this will get tested on hardware before merging. Normally I would be happy to do it, but I will not have access to my hardware for a free weeks. Good luck!

@jcerise
Copy link
Contributor Author

jcerise commented May 3, 2022

Thanks so much for the feedback! I addressed everything as best I could. I saw another contributor say this earlier in a different PR, but this is legitimately the best first experience I have had with a project like this. I really appreciate the time and care taken to address this PR.

There's certainly some tribal knowledge that is now much clearer than when I started, and I learned a few things :)

I agree that testing on hardware would be good, I would be happy to jump forward and volunteer, but I started this at Pycon where there was hardware available, and unfortunately, I no longer have access to the hardware to test this. It is just type annotations though (aside from the requirements changes, and the new try/catch at the top) and should not (famous last words? I hope not :D ) affect the actual functionality of this library. However, I would probably feel better waiting on having this merged until it can be properly tested.

@jerryneedell
Copy link
Contributor

@jcerise first of all, thank you for jumping in at PyCon to help with this. Don't let the comments of a curmudgeon like me dampen your enthusiasm ;-)
As I noted before, I'll defer to the other CircuitPython Librarians to comment and/or accept the "type" changes without testing. I don't fully understand what they are for or what impact they have on code size or execution.
I jumped in when executable code changes like the assert were added. I would argue that something like that clearly required on hardware testing.
If there are no changes to the code execution, again, I'll defer to others to make that call. I don't want to hold things up especially when I am unable to provide the testing.
My one concern is that the changes are adding to the code size enough to impact the feather_m0_rfm9x build of CIrcuitPython which includes this library as a "frozen" module. I would suggest that someone verify that it still builds with this PR. Again, I apologize that I am unable to do that myself at this time.

@tekktrik
Copy link
Member

tekktrik commented May 3, 2022

Big agree - thank you for jumping in to help at PyCon, @jcerise! Glad it's been an enjoyable experience - it should!

Type annotations are generally safe, but I would feel better building it if it's frozen in - I just never remember which libraries those are, so thank you @jerryneedell for mentioning that! I'll build it once it's ready to be safe.

I can take care of testing that, @jcerise, but if you're wondering what we mean by "frozen in", here's some information: https://learn.adafruit.com/building-circuitpython/adding-frozen-modules

Basically one build of the CircuitPython firmware has this cooked into it, so extra should be given to memory size (type annotations are ignored by the compiler I believe) and functionality (since this is cooked into firmware for specific boards, we get the benefit of the user not needed to provide this library, but it also means that any bugs will proliferate much more readily 😅)

@FoamyGuy
Copy link
Contributor

FoamyGuy commented May 3, 2022

Echoing what a few have said, thanks so much for working on this @jcerise!

My thoughts on a few things mentioned above:

Regarding suppressing mypy, I think we don't need to worry about it for now. We don't have the checks put into our CI yet so for the time being it's okay if it's still complaining about some things. When the time comes to add it to our CI checks we'll discuss the way we want to configure it which I assume will suppress any messages that we can't or don't intend to comply with.

regarding testing, we'll definitely test on hardware. I think I have some of the hardware to test this on. But it's also okay if we wait for a bit for jerry to return. I definitely believe that he's got more experience and hardware for testing more thoroughly than I.

We can do the frozen build test as well to make sure we won't run into size trouble. I'm not actually sure what impact the types have on final size of the mpy file. I think they may get stripped somewhere in the process but I'm not sure if the net impact is really 0 or maybe something more.

Copy link
Member

@tekktrik tekktrik left a comment

Choose a reason for hiding this comment

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

Just a few minor changes that I think got missed. After those, we can try building the firmware :)

@jcerise
Copy link
Contributor Author

jcerise commented May 4, 2022

Thanks for the patience here. I realize I maybe should have chosen a smaller file for my first attempt, but with the guidance and discussion here, this has been great. My apologies for the silly mistakes above, those have been ironed out.

@tekktrik
Copy link
Member

tekktrik commented May 4, 2022

Nah, no worries, thanks for the quick turnaround!

@tekktrik
Copy link
Member

tekktrik commented May 4, 2022

Builds the Feather M0 RFM9x!

185536 bytes used, 2624 bytes free in flash firmware space out of 188160 bytes (183.75kB).
9844 bytes used, 22924 bytes free in ram for stack and heap out of 32768 bytes (32.0kB).

Converted to uf2, output size: 371200, start address: 0x2000
Wrote 371200 bytes to build-feather_m0_rfm9x/firmware.uf2

Copy link
Member

@tekktrik tekktrik left a comment

Choose a reason for hiding this comment

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

Small question for @FoamyGuy

@tekktrik
Copy link
Member

tekktrik commented May 9, 2022

Looks good to me! I'd approve it at this point, but it looks @FoamyGuy has it from here for testing, so it'll just get merged afterwards. Thanks @jcerise!

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.

I tested several of the examples included in the repo successfully with https://www.adafruit.com/product/3231 on PyGamer, EdgeBadge, and Feather RP2040 all on 7.3.0-beta.2

@FoamyGuy FoamyGuy merged commit 2d8310f into adafruit:main May 9, 2022
@FoamyGuy
Copy link
Contributor

FoamyGuy commented May 9, 2022

Thanks again for working on this @jcerise!

adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request May 10, 2022
Updating https://github.com/adafruit/Adafruit_CircuitPython_BNO055 to 5.4.1 from 5.4.0:
  > change discord badge
  > Patch: Replaced discord badge image
  > Updated gitignore
  > Update Black to latest.

Updating https://github.com/adafruit/Adafruit_CircuitPython_RFM9x to 2.2.4 from 2.2.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_RFM9x#73 from jcerise/65/missing_type_annotations
  > change discord badge
  > Patch: Replaced discord badge image
  > Updated gitignore
  > Update Black to latest.
  > Fixed readthedocs build
  > Consolidate Documentation sections of README

Updating https://github.com/adafruit/Adafruit_CircuitPython_ImageLoad to 1.16.1 from 1.16.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_ImageLoad#60 from matt-land/add-typing

Updating https://github.com/adafruit/Adafruit_CircuitPython_JWT to 1.2.6 from 1.2.5:
  > Merge pull request adafruit/Adafruit_CircuitPython_JWT#11 from ktkinsey37/typing
  > change discord badge
  > Patch: Replaced discord badge image
  > Updated gitignore
  > Update Black to latest.
  > Fixed readthedocs build
  > Consolidate Documentation sections of README

Updating https://github.com/adafruit/Adafruit_CircuitPython_PIOASM to 0.7.2 from 0.7.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_PIOASM#47 from jepler/example-updates-background
  > Merge pull request adafruit/Adafruit_CircuitPython_PIOASM#46 from jepler/neopixel-match-core
  > Merge pull request adafruit/Adafruit_CircuitPython_PIOASM#45 from jepler/background-morse
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.

Missing Type Annotations
4 participants