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

Fix static typing checks #75

Merged
merged 9 commits into from Oct 18, 2022
Merged

Fix static typing checks #75

merged 9 commits into from Oct 18, 2022

Conversation

pabluk
Copy link
Collaborator

@pabluk pabluk commented Oct 15, 2022

In order to make the CI green again 😅 this PR fix all the type hint errors reported by mypy on the CI workflow.

$ mypy --ignore-missing-imports
Found 24 errors in 6 files (checked 38 source files)

Maybe could be a good idea to add a branch protection rule to only allow/enforce merges on the main branch if CI checks are green, to avoid re-doing this work in a future. I don't know all the history behind the project/repo and the reasons to adopt static typing but it could require some additional when importing code from another code base.

Please, don't hesitate to suggest any changes or to reject this PR if it's not relevant/useful.

mypy throws this error because the 2nd lambda function doesn't
handle the case of re.search() returning None.
The `get_key` function also requires two `assert` statements to
provide more hints to mypy and keep the previous behaviour when:

 1. `key_name` doesn't exist into `device`
 2. re.search() will always find a group (`0`)
As described on python/mypy#7178 (comment)
isn't possible to use dynamic keys with TypedDict and the recommendation
is to use `# type: ignore [misc]`.
If the result of re.search()[0] is not indexable (returns `None`) it will
be handled by the try/except block, so it can be safely ignored.
But maybe it could be rewritten to handle this in a clear way.
Add type annotation for `seen` variable.
@pabluk pabluk requested a review from AirLoren October 15, 2022 11:27
@pabluk
Copy link
Collaborator Author

pabluk commented Oct 15, 2022

Just for the record, the "Check static typing" step is now passing without errors

Run mypy --ignore-missing-imports tools
Success: no issues found in 38 source files

but the CI is still red due to a missing Python dependency (matplotlib) in "Run tests" (requiring another dedicated PR).

C.f https://github.com/Boavizta/environmental-footprint-data/actions/runs/3255511551/jobs/5344902062

@pabluk pabluk mentioned this pull request Oct 16, 2022
@AirLoren
Copy link
Contributor

I need some time to check everything before merge but thanks a lot @pabluk for your work.

@pabluk
Copy link
Collaborator Author

pabluk commented Oct 17, 2022

I need some time to check everything before merge but thanks a lot @pabluk for your work.

Yes, no problem, and if you have any questions or if you see other approaches to fix things I would be happy to help with that.

@AirLoren AirLoren merged commit 43ad0f9 into main Oct 18, 2022
@AirLoren
Copy link
Contributor

Thank you @pabluk

@AirLoren
Copy link
Contributor

@pabluk I also fixed parsers unit tests and CI is now green again. ;-)

@AirLoren AirLoren deleted the fix-type-hint-messages branch October 19, 2022 07:00
@pabluk
Copy link
Collaborator Author

pabluk commented Oct 19, 2022

@pabluk I also fixed parsers unit tests and CI is now green again. ;-)

Great news!! now we can continue to improve the Apple parser and the whole project safely 🚀

@AirLoren thanks for your time reviewing all those PR

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.

None yet

2 participants