Skip to content

Type annotations and suspected minor bug fix #34

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 10 commits into from
May 6, 2024
Merged

Conversation

RossK1
Copy link
Contributor

@RossK1 RossK1 commented Apr 25, 2023

Mostly addition of type annotations, but one commit to fix a suspected bug.
The open function was trying to add an attribute to the file_name variable. This variable was also later never used. Above in the code, the same pattern is used to set the variable on the file_state dictionary instead, which is used. So I presume this was the intended code here too.

@RossK1
Copy link
Contributor Author

RossK1 commented Apr 25, 2023

Should be good to resolve #22 .
There is a bit of a workaround in the typing of arguments to the builtin "open" method. This should be of type FileDescriptorOrPath from the _typeshed package. This package is in the stdlib, but not in older versions of Python. As such, a type alias for it was defined and used instead. Once circuitpython only supports versions of python that include _typeshed, then it can be switched over as indicated in the code comments.

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.

Thanks for the submission, super awesome! Feedback below!

with open(file_name, "r") as file_state[ # pylint: disable=unspecified-encoding
"f"
]:
file_state = {"line": 0, "ext_addr": 0, "eof": False, "f": TextIOWrapper}
Copy link
Member

Choose a reason for hiding this comment

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

Since it's going to get replaced, you could just make the "f" key equal to None and not import TextIOWrapper.

Copy link
Contributor

Choose a reason for hiding this comment

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

I did move FileState into a TypedDict and change the initial value to None. But also kept TextIOWrapper imported and set the type of f in the TypedDict to Optional[TextIOWrapper] so that it shows the possible values of None or an open file.

If there is a better way to do that we can make further changes in a follow up PR.

@tekktrik tekktrik linked an issue Apr 27, 2023 that may be closed by this pull request
13 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.

This is looking good to me at this point.

I pushed a few commits that make changes based on the prior review feedback.

I tested this branch successfully on a Feather RP2040 using the avrprog_program_uno328.py example script. It ran and seems to have successfully loaded the optiboot file.

@FoamyGuy FoamyGuy merged commit 8a19b59 into adafruit:main May 6, 2024
1 check passed
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request May 7, 2024
Updating https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI to 8.1.1 from 8.1.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_ESP32SPI#201 from adafruit/connect_dgram_mode

Updating https://github.com/adafruit/Adafruit_CircuitPython_ILI9341 to 1.5.0 from 1.4.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_ILI9341#38 from RetiredWizard/main

Updating https://github.com/adafruit/Adafruit_CircuitPython_LIS3MDL to 1.2.0 from 1.1.27:
  > Merge pull request adafruit/Adafruit_CircuitPython_LIS3MDL#26 from ContosChaos/patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_AVRprog to 1.5.1 from 1.5.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_AVRprog#34 from RossK1/main

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.

Missing Type Annotations
4 participants