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
Conversation
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.
Just for the record, the "Check static typing" step is now passing without errors
but the CI is still red due to a missing Python dependency ( C.f https://github.com/Boavizta/environmental-footprint-data/actions/runs/3255511551/jobs/5344902062 |
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. |
Thank you @pabluk |
@pabluk I also fixed parsers unit tests and CI is now green again. ;-) |
In order to make the CI green again 😅 this PR fix all the type hint errors reported by
mypy
on the CI workflow.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.