From 26173c243a37482d46e93478410417f099e0f77c Mon Sep 17 00:00:00 2001 From: grdddj Date: Fri, 26 Nov 2021 14:18:30 +0100 Subject: [PATCH] feat(python): enable pyright-based type checking --- Makefile | 2 ++ python/.changelog.d/1893.added | 1 + python/Makefile | 14 ++++++++++++++ python/pyrightconfig.json | 12 ++++++++++++ python/setup.cfg | 6 ++++++ 5 files changed, 35 insertions(+) create mode 100644 python/.changelog.d/1893.added create mode 100644 python/pyrightconfig.json diff --git a/Makefile b/Makefile index 9905ba4c3..02c09bb7b 100644 --- a/Makefile +++ b/Makefile @@ -29,6 +29,7 @@ pystyle_check: ## run code style check on application sources and tests @black --check $(PY_FILES) @echo [PYLINT] @pylint $(PY_FILES) + @echo [PYTHON] make -C python style_check pystyle: ## apply code style on application sources and tests @@ -42,6 +43,7 @@ pystyle: ## apply code style on application sources and tests @flake8 $(PY_FILES) @echo [PYLINT] @pylint $(PY_FILES) + @echo [PYTHON] make -C python style changelog_check: ## check changelog format diff --git a/python/.changelog.d/1893.added b/python/.changelog.d/1893.added new file mode 100644 index 000000000..25e9a4187 --- /dev/null +++ b/python/.changelog.d/1893.added @@ -0,0 +1 @@ +Full type hinting checkable with pyright diff --git a/python/Makefile b/python/Makefile index d3b2bf507..024dd8702 100644 --- a/python/Makefile +++ b/python/Makefile @@ -49,10 +49,24 @@ style: isort --apply --recursive $(STYLE_TARGETS) --skip-glob "$(EXCLUDE_TARGETS)/*" autoflake -i --remove-all-unused-imports -r $(STYLE_TARGETS) --exclude "$(EXCLUDE_TARGETS)" flake8 + pyright style_check: black --check $(STYLE_TARGETS) isort --check-only --recursive $(STYLE_TARGETS) --skip-glob "$(EXCLUDE_TARGETS)/*" flake8 + pyright .PHONY: all build install clean style style_check git-clean clean-build clean-pyc clean-test + +test: + pytest tests + +mypy: + mypy --config-file ./setup.cfg ./src/trezorlib/ + +mypy_report: + mypy --config-file ./setup.cfg ./src/trezorlib/ --html-report mypy_report + +pyright: + pyright -p pyrightconfig.json diff --git a/python/pyrightconfig.json b/python/pyrightconfig.json new file mode 100644 index 000000000..c9b9cd4c7 --- /dev/null +++ b/python/pyrightconfig.json @@ -0,0 +1,12 @@ +{ + "include": [ + "src/trezorlib", + "tools", + "helper-scripts" + ], + "typeCheckingMode": "basic", + "reportMissingImports": false, + "reportUntypedFunctionDecorator": true, + "reportUntypedClassDecorator": true, + "reportMissingParameterType": true +} diff --git a/python/setup.cfg b/python/setup.cfg index 5dcfcaacb..426f6fdca 100644 --- a/python/setup.cfg +++ b/python/setup.cfg @@ -37,3 +37,9 @@ not_skip=__init__.py known_first_party=trezorlib known_third_party=hidapi, rlp, ethjsonrpc, ecdsa, mnemonic, shamir_mnemonic, requests, click, pyblake2, \ usb, construct, pytest + +[mypy] +check_untyped_defs = True +show_error_codes = True +warn_unreachable = True +disable_error_code = import