diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index cbbef734..8e95b52b 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -38,6 +38,9 @@ jobs: - id: flake8 run: make flake8 + - id: mypy + run: make mypy + - id: pyLint run: make pylint diff --git a/Makefile b/Makefile index 9ef62923..7e5c7c4b 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ all: $(generated) aiven/client/version.py: .git/index $(PYTHON) version.py $@ -test: flake8 pylint pytest +test: flake8 mypy pylint pytest reformat: $(PYTHON) -m isort --recursive $(PYTHON_DIRS) @@ -29,6 +29,9 @@ validate-style: flake8: $(PYTHON) -m flake8 $(PYTHON_DIRS) +mypy: + $(PYTHON) -m mypy $(PYTHON_DIRS) + pylint: $(PYTHON) -m pylint $(PYTHON_DIRS) @@ -44,7 +47,7 @@ clean: build-dep-fedora: sudo dnf install -y --best --allowerasing python3-devel python3-flake8 python3-requests \ - tar rpmdevtools python3-pylint python3-isort python3-pytest + tar rpmdevtools python3-mypy python3-pylint python3-isort python3-pytest .PHONY: rpm rpm: $(RPM) @@ -64,4 +67,4 @@ $(RPM): $(generated) install-rpm: $(RPM) sudo dnf install $< -.PHONY: build-dep-fedora clean coverage pytest pylint flake8 reformat test validate-style +.PHONY: build-dep-fedora clean coverage pytest mypy pylint flake8 reformat test validate-style diff --git a/aiven-client.spec b/aiven-client.spec index 97045924..f900bf2c 100644 --- a/aiven-client.spec +++ b/aiven-client.spec @@ -7,7 +7,7 @@ License: ASL 2.0 Source0: rpm-src-aiven-client.tar BuildArch: noarch Requires: python3-requests -BuildRequires: python3-devel, python3-flake8, python3-pylint, python3-pytest +BuildRequires: python3-devel, python3-flake8, python3-mypy, python3-pylint, python3-pytest %description diff --git a/aiven/__init__.py b/aiven/__init__.py index b36383a6..05427e16 100644 --- a/aiven/__init__.py +++ b/aiven/__init__.py @@ -1,3 +1,3 @@ from pkgutil import extend_path -__path__ = extend_path(__path__, __name__) +__path__ = extend_path(__path__, __name__) # type: ignore # mypy issue #1422 diff --git a/aiven/client/__main__.py b/aiven/client/__main__.py index 96a378e2..24d4e07a 100644 --- a/aiven/client/__main__.py +++ b/aiven/client/__main__.py @@ -1,7 +1,8 @@ from .cli import AivenCLI +from typing import NoReturn -def main(): +def main() -> NoReturn: AivenCLI().main() diff --git a/aiven/client/argx.py b/aiven/client/argx.py index 5c435166..14dd3627 100644 --- a/aiven/client/argx.py +++ b/aiven/client/argx.py @@ -3,7 +3,7 @@ # This file is under the Apache License, Version 2.0. # See the file `LICENSE` for details. from aiven.client import envdefault, pretty -from typing import Optional +from typing import NoReturn, Optional import aiven.client.client import argparse @@ -302,7 +302,7 @@ def run_actual(self, args_for_help): self.pre_run(func) return func() # pylint: disable=not-callable - def main(self, args=None): + def main(self, args=None) -> NoReturn: # TODO: configurable log level logging.basicConfig(level=logging.INFO, format=LOG_FORMAT) logging.getLogger("requests").setLevel(logging.WARNING) diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 00000000..4601820f --- /dev/null +++ b/mypy.ini @@ -0,0 +1,26 @@ +# Global configuration + +[mypy] +python_version = 3.7 +warn_redundant_casts = True + +# Disable errors on the code which is not annotated yet + +[mypy-aiven.client.*] +ignore_errors = True + +[mypy-tests.*] +ignore_errors = True + +[mypy-aiven.client.__main__] +ignore_errors = False +disallow_untyped_defs = True +disallow_incomplete_defs = True +check_untyped_defs = True +no_implicit_optional = True +warn_unused_ignores = True +warn_no_return = True +warn_unreachable = True +strict_equality = True +ignore_missing_imports = True + diff --git a/requirements.dev.txt b/requirements.dev.txt index 0b2cbfaa..ffc6ef78 100644 --- a/requirements.dev.txt +++ b/requirements.dev.txt @@ -1,4 +1,6 @@ flake8 +# Lock mypy to the same version used in downstream build environments +mypy==0.910 # Lock pylint to the same version used in downstream build environments pylint==2.6.0 pytest