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

Remove reassigning variables with new types, pass Mypy #66

Merged
merged 2 commits into from
Apr 25, 2023

Conversation

matt-land
Copy link
Contributor

@matt-land matt-land commented Apr 24, 2023

Changes:

  • Minor fixes for "Local variable 'x' might be referenced before assignment" for [width, height] in png.py
  • Make function documentation of parameters match type hints where they disagreed or looked out of date
  • Fix in gif.py, png.py where optional arguments were assumed truthy (and called) (Mypy arg-type error)
  • Function arguments that are optional are changed to be explicit instead of implicit (PEP 484)
    before
    def foo(some_arg: Tree = None):
    after
    def foo(some_Arg: Optional[Tree] = None):
  • references that were re-assigned with new types are removed (Mypy "assignment" errors). This was usually from callables to objects, but there are other examples fixed in this pr also. This was also super confusing to contributors. (Issue Possible removal of 'type juggling' of references (mypy related) #59 )

before:

if palette:
    palette = callable(...)  # type: Palette
...
return palette, bitmap

after:

palette_obj = None
if palette:
    palette_obj = callable(...)
...
return palette_obj, bitmap_obj

before:

palette_colors = set()
while something:
    palette.add(<observed color>)
if bitmap:
    palette_colors = list(palette_colors)  # type: List[int]
    bitmap_obj[x, y] = palette_colors.index(pixel)

after:

palette_colors = set()
while something:
    palette.add(<observed color>)
if bitmap:
    bitmap_obj[x, y] = list(palette_colors).index(pixel)

Testing

pipenv shell
pipenv install requirements.txt
mypy .
> Success: no issues found in 16 source files

@matt-land matt-land force-pushed the remove-type-changes branch from a0f5079 to 378e8e2 Compare April 24, 2023 15:45
@matt-land matt-land changed the title work for #59 to remove changing types of objects when reassigning WIP for #59 Remove reassigning variables with new types (mypy) Apr 24, 2023
@matt-land matt-land force-pushed the remove-type-changes branch 3 times, most recently from 276466e to dc4bb0b Compare April 24, 2023 17:18
@matt-land matt-land changed the title WIP for #59 Remove reassigning variables with new types (mypy) Remove reassigning variables with new types, pass Mypy Apr 24, 2023
@matt-land matt-land force-pushed the remove-type-changes branch from dc4bb0b to c4c4d67 Compare April 24, 2023 17:52
…ning

rename, remove type overrides

more implicit types, and non-matching return types

mypy caught errors
@matt-land matt-land force-pushed the remove-type-changes branch from c4c4d67 to 7ded8d1 Compare April 24, 2023 17:56
@matt-land
Copy link
Contributor Author

@FoamyGuy @kattni Please take a look

@tekktrik tekktrik requested a review from a team April 24, 2023 18:45
@FoamyGuy
Copy link
Contributor

I did a quick pass over the changes this morning and it's looking good to me so far. Thanks for the readability and other improvements @matt-land!

I'll take another look and test it out later tonight.

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.

This looks good to me. Thanks again @matt-land!

I tested this version successfully on a Feather S2 TFT with a handful of the example scripts and images in this repo.

I've reverted the pre-commit config change for now. I'll make a note in the weeds for the meeting next week to discuss with @kattni and the team how we want to plan to roll out the change to start running mypy and the configuration and versions that it'll use.

@FoamyGuy FoamyGuy merged commit 1ae6b2c into adafruit:main Apr 25, 2023
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Apr 26, 2023
Updating https://github.com/adafruit/Adafruit_CircuitPython_IRRemote to 4.1.14 from 4.1.13:
  > Merge pull request adafruit/Adafruit_CircuitPython_IRRemote#64 from dhalbert/handle-failedtodecode

Updating https://github.com/adafruit/Adafruit_CircuitPython_LSM6DS to 4.5.8 from 4.5.7:
  > Merge pull request adafruit/Adafruit_CircuitPython_LSM6DS#60 from zachariahpifer/fix_linear_and_angular_rates
  > Add upload url to release action
  > Add .venv to .gitignore

Updating https://github.com/adafruit/Adafruit_CircuitPython_HTTPServer to 3.0.2 from 3.0.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_HTTPServer#51 from jrrickerson/add_simpletest_example

Updating https://github.com/adafruit/Adafruit_CircuitPython_ImageLoad to 1.17.1 from 1.17.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_ImageLoad#66 from matt-land/remove-type-changes
  > Add upload url to release action

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Updated download stats for the libraries
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.

2 participants