diff --git a/.github/workflows/qa.yml b/.github/workflows/qa.yml index aa4343315..571ead8eb 100644 --- a/.github/workflows/qa.yml +++ b/.github/workflows/qa.yml @@ -16,6 +16,7 @@ jobs: matrix: toxenv: - checkqa + - mypy - readme python-version: - "3.x" diff --git a/piptools/logging.py b/piptools/logging.py index 87c552667..cc9828c24 100644 --- a/piptools/logging.py +++ b/piptools/logging.py @@ -12,7 +12,7 @@ class LogContext: stream = sys.stderr - def __init__(self, verbosity=0, indent_width=2): + def __init__(self, verbosity: int = 0, indent_width: int = 2): self.verbosity = verbosity self.current_indent = 0 self._indent_width = indent_width diff --git a/piptools/py.typed b/piptools/py.typed new file mode 100644 index 000000000..e69de29bb diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py index f9e26ea0a..c861838bb 100755 --- a/piptools/scripts/compile.py +++ b/piptools/scripts/compile.py @@ -3,6 +3,7 @@ import sys import tempfile import warnings +from typing import Any from click import Command from click.utils import safecall @@ -25,7 +26,7 @@ DEFAULT_REQUIREMENTS_OUTPUT_FILE = "requirements.txt" -def _get_default_option(option_name): +def _get_default_option(option_name: str) -> Any: """ Get default value of the pip's option (including option from pip.conf) by a given option name. diff --git a/piptools/utils.py b/piptools/utils.py index 1b2560b70..e6f9cef47 100644 --- a/piptools/utils.py +++ b/piptools/utils.py @@ -43,7 +43,7 @@ def key_from_req(req): return key -def comment(text): +def comment(text: str) -> str: return style(text, fg="green") diff --git a/setup.cfg b/setup.cfg index 710868286..5f30716e6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -69,3 +69,17 @@ pytest-parametrize-values-row-type = tuple [isort] profile = black + +[mypy] +disallow_any_generics = true +disallow_incomplete_defs = true +disallow_subclassing_any = true +disallow_untyped_calls = true +disallow_untyped_decorators = true +ignore_missing_imports = true +no_implicit_optional = true +strict_equality = true +warn_redundant_casts = true +warn_return_any = true +warn_unused_configs = true +warn_unused_ignores = true diff --git a/tox.ini b/tox.ini index d3f9d736c..893d43e7c 100644 --- a/tox.ini +++ b/tox.ini @@ -3,6 +3,7 @@ envlist = # NOTE: keep this in sync with the env list in .github/workflows/ci.yml. py{36,37,38,39,py,py3}-pip{20.1,20.2,20.3,previous,latest,master}-coverage checkqa + mypy readme skip_missing_interpreters = True @@ -33,6 +34,11 @@ deps = pre-commit commands_pre = commands = pre-commit run --all-files --show-diff-on-failure +[testenv:mypy] +deps = mypy +commands_pre = +commands = mypy piptools + [testenv:readme] deps = twine commands_pre =