Skip to content

Add infrastructure for type checking in Python code #68

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 5 commits into from
Dec 21, 2023
Merged

Add infrastructure for type checking in Python code #68

merged 5 commits into from
Dec 21, 2023

Conversation

per1234
Copy link
Collaborator

@per1234 per1234 commented Dec 21, 2023

Type annotations are provided in the project's Python code to indicate the types of objects (#53). Previously no infrastructure was provided to leverage or validate these annotations.

A task is added here to allow contributors to easily check for typing problems using the mypy tool.

A new job is added to the "Check Python" GitHub Actions workflow to run the task on every push or pull request that modifies relevant files.

Type annotations are provided in the project's Python code to indicate the types of objects. Previously no
infrastructure was provided to leverage or validate these annotations.

A task is added here to allow contributors to easily check for typing problems using the mypy tool.

A new job is added to the "Check Python" GitHub Actions workflow to run the task on every push or pull request that
modifies relevant files.
The annotation was invalid, resulting in mypy error:

error: "dict" expects 2 type arguments, but 1 given  [type-arg]

The `headers` field of the dictionary returned by this function is a `http.client.HTTPMessage` class object, while the
other field values are strings. I didn't find a way to specify this in a return type annotation and the current approach
is to provide annotations on a "best effort" basis (vs making them universally mandatory) so I settled on removing the
annotation entirely.
The type of the `data` parameter of `urllib.request.Request` is bytes. Previously the type annotations for the method
parameters used to pass the data passed via this parameter were the incorrect type `str`.
Some of the code uses practice of reusing a variable through a chain of processing its contents in some cases the
variable type was changed over the course of the processing. This caused the type checking via mypy to fail.

The code is reworked to avoid any changing of variable type.
@per1234 per1234 added type: enhancement Proposed improvement topic: infrastructure Related to project infrastructure labels Dec 21, 2023
@per1234 per1234 self-assigned this Dec 21, 2023
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (19f5e91) 100.00% compared to head (ba7c42a) 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #68   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            2         2           
  Lines          732       729    -3     
=========================================
- Hits           732       729    -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@per1234 per1234 merged commit 0d14d3a into arduino:main Dec 21, 2023
@per1234 per1234 deleted the mypy branch January 20, 2024 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: infrastructure Related to project infrastructure type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants