diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 552d29cea..1af47cfe8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,6 +17,13 @@ repos: language_version: python3 additional_dependencies: - flake8-pytest-style + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v0.790 + hooks: + - id: mypy + # Avoid error: Duplicate module named 'setup' + # https://github.com/python/mypy/issues/4008 + exclude: ^tests/test_data/ - repo: https://github.com/PyCQA/bandit rev: 1.7.0 hooks: 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