Skip to content

add type annotations #18 #23

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 3 commits into from
May 23, 2022
Merged

add type annotations #18 #23

merged 3 commits into from
May 23, 2022

Conversation

matt-land
Copy link
Contributor

@matt-land matt-land commented May 3, 2022

Adding type hints for functions. This does not currently pass all mypy. The 4 remaining issues are as follows (and beyond my expertise):

mypy .
adafruit_bitmapsaver.py:101: error: Unsupported operand types for & ("None" and "int")
adafruit_bitmapsaver.py:101: note: Left operand is of type "Union[int, None, Any]"
adafruit_bitmapsaver.py:102: error: Unsupported operand types for >> ("None" and "int")
adafruit_bitmapsaver.py:102: note: Left operand is of type "Union[int, None, Any]"
adafruit_bitmapsaver.py:109: error: Value of type "Union[Any, bytearray, memoryview, array[Any], ndarray, RGBMatrix]" is not indexable
adafruit_bitmapsaver.py:138: error: Module has no attribute "DISPLAY"
Found 4 errors in 1 file (checked 1 source file)

@matt-land matt-land changed the title #18 add type annotations add type annotations #18 May 3, 2022
@tekktrik tekktrik requested a review from a team May 3, 2022 20:59
@tekktrik tekktrik linked an issue May 3, 2022 that may be closed by this pull request
7 tasks
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.

Thanks for working on this @matt-land I noted a few potential changes in some different sections of the code, but this is looking pretty good to me overall.

def _write_pixels(
output_file: BufferedWriter,
pixel_source: Union[Bitmap, Display],
palette: Optional[Palette],
Copy link
Contributor

Choose a reason for hiding this comment

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

Is palette really optional here? it doesn't default to None and it looks like there is an attempt to access a value from it using square brackets inside of this function without any further check for None that I'm seeing.

Copy link
Contributor Author

@matt-land matt-land May 10, 2022

Choose a reason for hiding this comment

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

I think Palette is optional. The function takes either a (bitmap & palette) and follows the first major branch or (Display & None) and follows the second major branch of the function.

Related: I added and "# handled by save_pixel's guardians" after I figured this out

Should I make palette default to None? or remove the Optional type decorator?

@matt-land matt-land force-pushed the add-typing branch 2 times, most recently from ab4244d to d61c5ed Compare May 10, 2022 02:31
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 again @matt-land

We'll keep the mypy ini file for now and adjust as needed when something is rolled out across all of the libraries.

@FoamyGuy FoamyGuy merged commit ab5ea17 into adafruit:main May 23, 2022
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request May 24, 2022
Updating https://github.com/adafruit/Adafruit_CircuitPython_BH1750 to 1.1.0 from 1.0.7:
  > Merge pull request adafruit/Adafruit_CircuitPython_BH1750#6 from DeadSix27/main
  > Patch .pre-commit-config.yaml
  > 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_CircuitPlayground to 5.2.1 from 5.2.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_CircuitPlayground#117 from Neradoc/frozen-module-subdirectory

Updating https://github.com/adafruit/Adafruit_CircuitPython_DS1307 to 2.1.10 from 2.1.9:
  > Merge pull request adafruit/Adafruit_CircuitPython_DS1307#24 from coplate/main
  > Patch .pre-commit-config.yaml
  > 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_UC8151D to 1.1.0 from 1.0.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_UC8151D#4 from HDR/main
  > Patch .pre-commit-config.yaml
  > change discord badge
  > Patch: Replaced discord badge image
  > Updated gitignore
  > Update Black to latest.
  > Fixed readthedocs build
  > Post-patch cleanup
  > Consolidate Documentation sections of README

Updating https://github.com/adafruit/Adafruit_CircuitPython_BitmapSaver to 1.2.1 from 1.2.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_BitmapSaver#23 from matt-land/add-typing
  > Patch .pre-commit-config.yaml
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
2 participants