Skip to content

Commit

Permalink
typing: add type checks for the first module
Browse files Browse the repository at this point in the history
This change is the beginning of fully annotating Aiven Client. Install
mypy, add mypy config file with everything ignored, except for the one
module, add target to Makefile, enable checks in GitHub Actions.

Partial implementation of #258.
  • Loading branch information
Roman Inflianskas committed Jan 17, 2022
1 parent 2f6b8bb commit 63f1ad8
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ jobs:
- id: flake8
run: make flake8

- id: mypy
run: make mypy

- id: pyLint
run: make pylint

Expand Down
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -29,6 +29,9 @@ validate-style:
flake8:
$(PYTHON) -m flake8 $(PYTHON_DIRS)

mypy:
$(PYTHON) -m mypy $(PYTHON_DIRS)

pylint:
$(PYTHON) -m pylint $(PYTHON_DIRS)

Expand All @@ -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)
Expand All @@ -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
2 changes: 1 addition & 1 deletion aiven-client.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion aiven/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from pkgutil import extend_path

__path__ = extend_path(__path__, __name__)
__path__ = extend_path(__path__, __name__) # type: ignore # mypy issue #1422
3 changes: 2 additions & 1 deletion aiven/client/__main__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from .cli import AivenCLI
from typing import NoReturn


def main():
def main() -> NoReturn:
AivenCLI().main()


Expand Down
4 changes: 2 additions & 2 deletions aiven/client/argx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
26 changes: 26 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -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

2 changes: 2 additions & 0 deletions requirements.dev.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 63f1ad8

Please sign in to comment.