Message ID | 20240927-vfazio-mypy-v1-0-91a7c2e20884@xes-inc.com |
---|---|
Headers | show |
Series | bindings: python: conform to mypy and ruff linter recommendations | expand |
On Fri, Sep 27, 2024 at 9:05 PM Vincent Fazio <vfazio@xes-inc.com> wrote: > > This patch series employs mypy [0] and ruff [1] to ensure the gpiod > library has correctly typed public interfaces, is performing proper type > checking internally, is consistently formatted in a standard code style > that targets Python 3.9 syntax, and passes a subset of linting checks. > > Patches 1 and 2 remove unused imports, sort the remainder, and ensure > the publicly usable classes are available from the gpiod base module. > > Patches 3 and 4 fix and add annotations to the gpiod bindings. > > Patches 5-13 fix type and lint errors internal to the bindings. > > Patch 14 fixes a duplicate test name identified by the linter. > > Patch 15 and 16 remove unused imports, sort the remainder, and fix lint > errors related to a shadowed export. > > Patches 17 and 18 fix and add annotations to the test gpiod bindings. > > Patches 19-21 fix type and lint errors internal to the tests. > > Patch 22 adds mypy and ruff configuration to pyproject.toml and adds > documentation to the readme so future patches can be evaluated against a > standard set of rules. > > There should be no functional changes that impact existing code as part > of this series. > > All unit tests continue to pass without changes and code coverage has > not changed. > > After this series is applied, the public type annotations will reflect > the argument expectations of the class methods so consumers can type > check their code against the gpiod type annotations. > > [0]: https://mypy.readthedocs.io/en/stable/ > [1]: https://docs.astral.sh/ruff/ > > Signed-off-by: Vincent Fazio <vfazio@xes-inc.com> > --- Phew! Nice work! My main concern is the lack of proper commit messages which makes some of the changes confusing to me - an intermediate python developer. I added some other requests, some commits will need splitting into two but overall this looks nice and I'll be happy to pick it up. Bart
This patch series employs mypy [0] and ruff [1] to ensure the gpiod library has correctly typed public interfaces, is performing proper type checking internally, is consistently formatted in a standard code style that targets Python 3.9 syntax, and passes a subset of linting checks. Patches 1 and 2 remove unused imports, sort the remainder, and ensure the publicly usable classes are available from the gpiod base module. Patches 3 and 4 fix and add annotations to the gpiod bindings. Patches 5-13 fix type and lint errors internal to the bindings. Patch 14 fixes a duplicate test name identified by the linter. Patch 15 and 16 remove unused imports, sort the remainder, and fix lint errors related to a shadowed export. Patches 17 and 18 fix and add annotations to the test gpiod bindings. Patches 19-21 fix type and lint errors internal to the tests. Patch 22 adds mypy and ruff configuration to pyproject.toml and adds documentation to the readme so future patches can be evaluated against a standard set of rules. There should be no functional changes that impact existing code as part of this series. All unit tests continue to pass without changes and code coverage has not changed. After this series is applied, the public type annotations will reflect the argument expectations of the class methods so consumers can type check their code against the gpiod type annotations. [0]: https://mypy.readthedocs.io/en/stable/ [1]: https://docs.astral.sh/ruff/ Signed-off-by: Vincent Fazio <vfazio@xes-inc.com> --- Vincent Fazio (22): bindings: python: clean up imports and exports bindings: python: make internal a private submodule bindings: python: fix annotation of variable length tuples bindings: python: add missing method type annotations bindings: python: add type stubs for _ext bindings: python: annotate internal members of Chip bindings: python: fix Chip union-attr type errors bindings: python: annotate internal members of LineRequest bindings: python: fix LineRequest union-attr type errors bindings: python: convert lines to offsets in LineRequest bindings: python: cast return value of LineRequest.get_values bindings: python: raise exception type, not exception instance bindings: python: selectively use f-strings bindings: python: tests: fix duplicate test name bindings: python: tests: clean up imports and exports bindings: python: tests: make EventType private to prevent export bindings: python: tests: add type stubs for external modules bindings: python: tests: add missing type annotations bindings: python: tests: ignore purposeful type errors bindings: python: tests: annotate internal members bindings: python: tests: use f-strings bindings: python: configure and document dev dependencies bindings/python/README.md | 17 ++ bindings/python/gpiod/__init__.py | 83 ++++++-- bindings/python/gpiod/_ext.pyi | 93 +++++++++ .../python/gpiod/{internal.py => _internal.py} | 3 +- bindings/python/gpiod/chip.py | 56 ++++-- bindings/python/gpiod/chip_info.py | 6 +- bindings/python/gpiod/edge_event.py | 9 +- bindings/python/gpiod/exception.py | 4 +- bindings/python/gpiod/info_event.py | 11 +- bindings/python/gpiod/line.py | 5 +- bindings/python/gpiod/line_info.py | 10 +- bindings/python/gpiod/line_request.py | 80 +++++--- bindings/python/gpiod/line_settings.py | 15 +- bindings/python/pyproject.toml | 36 ++++ bindings/python/setup.py | 2 +- bindings/python/tests/__init__.py | 6 +- bindings/python/tests/__main__.py | 5 +- bindings/python/tests/gpiosim/__init__.py | 2 + bindings/python/tests/gpiosim/_ext.pyi | 21 +++ bindings/python/tests/gpiosim/chip.py | 3 +- bindings/python/tests/helpers.py | 6 +- bindings/python/tests/procname/__init__.py | 2 + bindings/python/tests/procname/_ext.pyi | 1 + bindings/python/tests/tests_chip.py | 105 ++++++----- bindings/python/tests/tests_chip_info.py | 38 ++-- bindings/python/tests/tests_edge_event.py | 66 ++++--- bindings/python/tests/tests_info_event.py | 100 ++++++---- bindings/python/tests/tests_line.py | 5 +- bindings/python/tests/tests_line_info.py | 49 +++-- bindings/python/tests/tests_line_request.py | 210 ++++++++++----------- bindings/python/tests/tests_line_settings.py | 19 +- bindings/python/tests/tests_module.py | 37 ++-- 32 files changed, 710 insertions(+), 395 deletions(-) --- base-commit: f6c8c3321d8f30979fa593a4f6546ff3dccd2549 change-id: 20240923-vfazio-mypy-2037e7d5bdd6 Best regards,